The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(storage): update schema validation and tests
Steven Enamakeld45781b21093
diff --git a/crates/openhuman-core/src/storage/import/layout_status_tests.rs b/crates/openhuman-core/src/storage/import/layout_status_tests.rsindex 8914aba1ac..b411bc5dd8 100644--- a/crates/openhuman-core/src/storage/import/layout_status_tests.rs+++ b/crates/openhuman-core/src/storage/import/layout_status_tests.rs@@ -42,6 +42,26 @@ fn reads_completed_versions_from_a_read_only_database_snapshot() {).unwrap();}+ let compressed = serde_json::json!({+ "owner": "compressed",+ "step": "large-step",+ "from": 0,+ "to": 4,+ "cursor": null,+ "written": 1,+ "done": true,+ "padding": "x".repeat(6000),+ })+ .to_string();+ let mut blob = vec![1];+ blob.extend(zstd::encode_all(compressed.as_bytes(), 3).unwrap());+ connection+ .execute(+ "INSERT INTO docs (scope, coll, id, updated_ms, body) \+ VALUES ('local', 'tsd.migrations', 'compressed', 400, ?1)",+ [rusqlite::types::Value::Blob(blob)],+ )+ .unwrap();connection.execute("INSERT INTO docs (scope, coll, id, updated_ms, body) \@@ -56,8 +76,12 @@ fn reads_completed_versions_from_a_read_only_database_snapshot() {assert_eq!(versions,- vec![("profiles".into(), 2), ("threads".into(), 3)]+ vec![+ ("compressed".into(), 4),+ ("profiles".into(), 2),+ ("threads".into(), 3)+ ]);- assert_eq!(last, Some(300));+ assert_eq!(last, Some(400));assert_eq!(std::fs::read(&db).unwrap(), original);}diff --git a/scripts/__tests__/check-storage-schema.test.mjs b/scripts/__tests__/check-storage-schema.test.mjsindex bdf81a7d85..0e70ff2158 100644--- a/scripts/__tests__/check-storage-schema.test.mjs+++ b/scripts/__tests__/check-storage-schema.test.mjs@@ -3,73 +3,78 @@ import test from 'node:test';import { lint, render } from '../ci/check-storage-schema.mjs';-const owner = (name, items, steps = []) => ({ owner: name, items, steps });const collection = (name, extra = {}) => ({- kind: 'collection',name,- version: 2,- scope: 'tenant',- index_fields: [],+ indexes: [],...extra,});test('a well-formed schema is clean', () => {const dump = {- owners: [- owner('cron', [collection('cron.jobs', { index_fields: ['next_run_ms'] })], [- { id: 'jobs_v2', item: 'cron.jobs', from: 1, to: 2, source: 'cron_jobs' },- ]),- owner('juice', [{ kind: 'blobs', name: 'juice/ccr/', scope: 'module' }]),+ collections: [+ collection('cron.jobs', {+ indexes: [{ name: 'by_time', fields: ['next_run_ms'], unique: false }],+ ttl_field: 'expires_ms',+ search: { fields: ['name', 'description'] },+ }),],};assert.deepEqual(lint(dump), []);});-test('names must be <owner>.<entity> in snake_case without a version suffix', () => {+test('collection names must be <owner>.<entity> in snake_case', () => {const problems = lint({- owners: [- owner('cron', [- collection('jobs'),- collection('cron.Jobs'),- collection('flows.runs'),- collection('cron.jobs_v2'),- ]),+ collections: [+ collection('jobs'),+ collection('Cron.Jobs'),+ collection('flows.runs'),],});- assert.equal(problems.length, 4, problems.join('\n'));+ assert.equal(problems.length, 3, problems.join('\n'));});-test('a name claimed by two owners is refused', () => {+test('duplicate collection and index names are refused', () => {const problems = lint({- owners: [owner('a', [{ kind: 'blobs', name: 'a/x/', scope: 'module' }]), owner('a', [])],+ collections: [+ collection('cron.jobs', {+ indexes: [+ { name: 'by_time', fields: ['created_ms'] },+ { name: 'by_time', fields: ['updated_ms'] },+ ],+ }),+ collection('cron.jobs'),+ ],});- assert.ok(problems.some(p => p.includes('declared twice')));+ assert.ok(problems.some(p => p.includes('collection "cron.jobs" is declared more than once')));+ assert.ok(problems.some(p => p.includes('index name "by_time" is empty or duplicated')));});test('indexed time fields must be epoch milliseconds', () => {const problems = lint({- owners: [owner('cron', [collection('cron.jobs', { index_fields: ['created_at', 'next_run_ms'] })])],+ collections: [collection('cron.jobs', {+ indexes: [{ name: 'by_time', fields: ['created_at', 'next_run_ms'] }],+ ttl_field: 'expires_at',+ })],});- assert.equal(problems.length, 1);+ assert.equal(problems.length, 2);assert.match(problems[0], /created_at/);+ assert.match(problems[1], /expires_at/);});-test('a step for an undeclared item or one that does not go up is refused', () => {- const problems = lint({- owners: [- owner('cron', [collection('cron.jobs')], [- { id: 'a', item: 'cron.nope', from: 1, to: 2 },- { id: 'b', item: 'cron.jobs', from: 2, to: 2 },- ]),+test('the rendering is stable and lists the composed collection declarations', () => {+ const dump = {+ collections: [+ collection('b.x'),+ collection('a.y', {+ indexes: [{ name: 'by_created', fields: ['created_ms'], unique: true }],+ search: { fields: ['title'] },+ }),],- });- assert.equal(problems.length, 2);-});--test('the rendering is stable and lists every owner', () => {- const dump = { owners: [owner('b', [collection('b.x')]), owner('a', [collection('a.y')])] };+ };const text = render(dump);- assert.ok(text.indexOf('## a') < text.indexOf('## b'));+ assert.ok(text.indexOf('`a.y`') < text.indexOf('`b.x`'));+ assert.match(text, /by_created/);+ assert.match(text, /Search fields/);assert.equal(render(dump), text);});@@ -85,9 +90,9 @@ test('the dump example builds with web3 by default and with an override that keeenv: { STORAGE_SCHEMA_FEATURES: 'core-product' },run: (_cmd, argv) => {args = argv;- return { status: 0, stdout: '{"owners":[]}', stderr: '' };+ return { status: 0, stdout: '{"collections":[]}', stderr: '' };},});- assert.deepEqual(dump, { owners: [] });+ assert.deepEqual(dump, { collections: [] });assert.equal(args[args.indexOf('--features') + 1], product);});diff --git a/scripts/ci/check-storage-schema.mjs b/scripts/ci/check-storage-schema.mjsindex 70769c057c..86055187bc 100644--- a/scripts/ci/check-storage-schema.mjs+++ b/scripts/ci/check-storage-schema.mjs@@ -30,8 +30,7 @@ const HERE = dirname(fileURLToPath(import.meta.url));export const REPO_ROOT = resolve(HERE, '..', '..');export const DOC_PATH = resolve(REPO_ROOT, 'docs', 'storage-schema.md');-const COLLECTION = /^[a-z][a-z0-9_]{1,23}\.[a-z][a-z0-9_]*$/;-const ENTITY = /^[a-z][a-z0-9_]*$/;+const COLLECTION = /^[a-z][a-z0-9_]*\.[a-z][a-z0-9_]*$/;const TIME_SUFFIX = /(_at|_ns|_us|_secs|_ts|_time)$/;/** Features the dump is built with: the contributor set plus the wallet owner. */