Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(qm,auth): v2 contract sits beside v1 at the vendored path; takeBindingFlags/parseAttestSources coverage (/ship)

garrytan80e03b835d8b
diff --git a/test/auth-binding-attest-sources.test.ts b/test/auth-binding-attest-sources.test.ts
new file mode 100644
index 0000000000..e75eb8469c
--- /dev/null
+++ b/test/auth-binding-attest-sources.test.ts
@@ -0,0 +1,27 @@
+/**
+ * Value: protects=--attest-sources parsing: sorted+deduped list, none clears (null), empty and invalid ids refused; fails_when=parseAttestSources stops deduping or sorting, drops the none/empty/id guards or --attest-sources stops being stripped from args;
+ * why_new=qm-scope-writes.test.ts drives bindCredential with a ready patch and never the CLI flag parser; seam=none; no_claim=brain checks of the listed sources (applyAttestSources, covered in qm-scope-writes; unit only).
+ * Test audit: gstack /ship Step 7 (GST-1113 train).
+ */
+import { describe, expect, test } from 'bun:test';
+import { takeBindingFlags } from '../src/commands/auth-binding.ts';
+
+describe('--attest-sources flag (takeBindingFlags)', () => {
+ test('a list is split, deduplicated and sorted, and the flag leaves the remaining args alone', () => {
+ const out = takeBindingFlags(['name-a', '--attest-actor', 'qm', '--attest-sources', 'scope-b, scope-a,scope-b', '--json']);
+ expect(out.args).toEqual(['name-a', '--json']);
+ expect(out.patch).toEqual({ attestActor: 'qm', attestSources: ['scope-a', 'scope-b'] });
+ });
+
+ test('the = form and none (clear) parse; none is null, not an empty list', () => {
+ expect(takeBindingFlags(['--attest-sources=scope-a']).patch).toEqual({ attestSources: ['scope-a'] });
+ expect(takeBindingFlags(['--attest-sources', 'none']).patch).toEqual({ attestSources: null });
+ });
+
+ test('a missing value, an empty list and an invalid source id are refused', () => {
+ expect(() => takeBindingFlags(['--attest-sources'])).toThrow(/requires a value/);
+ expect(() => takeBindingFlags(['--attest-sources', '--json'])).toThrow(/requires a value/);
+ expect(() => takeBindingFlags(['--attest-sources', ' , '])).toThrow(/at least one source/);
+ expect(() => takeBindingFlags(['--attest-sources', 'Not_Valid'])).toThrow(/Invalid source_id/);
+ });
+});
diff --git a/test/qm-memory-contract.test.ts b/test/qm-memory-contract.test.ts
index cd4e8c9164..fe6ff7f4c9 100644
--- a/test/qm-memory-contract.test.ts
+++ b/test/qm-memory-contract.test.ts
@@ -11,6 +11,7 @@
import { describe, expect, test } from 'bun:test';
import { createHash } from 'node:crypto';
import { readFileSync } from 'node:fs';
+import { join } from 'node:path';
import { ACTOR_REASON_FIXES, QM_CONTRACT_PATH, QM_CONTRACT_PATHS, renderQmMemoryContract } from '../scripts/build-qm-memory-contract.ts';
import { CODES } from '../src/core/error-registry.ts';
import { operations } from '../src/core/operations.ts';
@@ -77,6 +78,11 @@ describe('QM memory-provider contract v2 (GST-1094 scope read, GST-900)', () =>
expect(readFileSync(QM_CONTRACT_PATHS[2], 'utf8')).toBe(renderQmMemoryContract(2));
});
+ test('v2 is written beside v1 at the path QM vendors', () => {
+ expect(QM_CONTRACT_PATHS[2].endsWith(join('docs', 'contracts', 'qm-memory-provider', 'v2.json'))).toBe(true);
+ expect(QM_CONTRACT_PATHS[1].endsWith(join('docs', 'contracts', 'qm-memory-provider', 'v1.json'))).toBe(true);
+ });
+
test('the tool schemas are the ones MCP serves', () => {
const served = buildToolDefs(operations.filter(o => o.name === 'memory_recall' || o.name === 'memory_write'));
for (const tool of fixture.tools) {