Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(file_register): size_bytes carries no minimum annotation, since write arguments never take one (GST-927); the handler refuses a negative size

garrytan823b297305b9
diff --git a/src/core/operation-manifest.generated.ts b/src/core/operation-manifest.generated.ts
index 8db565957b..b0a5dcf7a7 100644
--- a/src/core/operation-manifest.generated.ts
+++ b/src/core/operation-manifest.generated.ts
@@ -3705,8 +3705,7 @@ export const OPERATION_MANIFEST: OperationMeta[] = [
},
"size_bytes": {
"type": "integer",
- "required": true,
- "minimum": 0
+ "required": true
},
"page_slug": {
"type": "string",
diff --git a/src/core/ops/files.ts b/src/core/ops/files.ts
index 4223cd87f0..91baca0eb5 100644
--- a/src/core/ops/files.ts
+++ b/src/core/ops/files.ts
@@ -265,7 +265,7 @@ const file_register: Operation = {
storage_path: { type: 'string', required: true, description: 'Where the host stored the object; must be the file_upload layout for page_slug, filename and content_hash' },
filename: { type: 'string', required: true },
content_hash: { type: 'string', required: true, description: 'SHA-256 of the bytes, 64 lowercase hex characters' },
- size_bytes: { type: 'integer', required: true, minimum: 0 },
+ size_bytes: { type: 'integer', required: true },
page_slug: { type: 'string', description: 'Page the file belongs to' },
mime_type: { type: 'string' },
},
diff --git a/test/file-register.test.ts b/test/file-register.test.ts
index cb34baff77..ee239d43c2 100644
--- a/test/file-register.test.ts
+++ b/test/file-register.test.ts
@@ -69,6 +69,17 @@ describe('file_register', () => {
expect(await fileRows(engine)).toBe(1);
});
+ test('an empty object registers with size 0, and a negative size refuses invalid_params and writes nothing', async () => {
+ const engine = await embedded();
+ await addPage(engine, 'notes/plan');
+ const empty = Buffer.alloc(0);
+ store('notes/plan/empty.txt', empty);
+ const params = { storage_path: 'notes/plan/empty.txt', filename: 'empty.txt', page_slug: 'notes/plan', content_hash: sha(empty), size_bytes: 0 };
+ expect(await run('file_register', ctxFor(engine), params)).toEqual({ status: 'registered', storage_path: 'notes/plan/empty.txt', size_bytes: 0 });
+ expect((await failure(() => run('file_register', ctxFor(engine), { ...params, storage_path: 'notes/plan/neg.txt', filename: 'neg.txt', size_bytes: -1 })))?.code).toBe('invalid_params');
+ expect(await fileRows(engine)).toBe(1);
+ });
+
test('records the page and source a registration belongs to, so purging that page in a non-default source finds it', async () => {
const engine = await embedded();
await engine.executeRaw("INSERT INTO sources (id, name) VALUES ('source-a', 'source-a') ON CONFLICT DO NOTHING");