From f5c32dff985b7984020799c8ffd741e3ceaedb95 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Thu, 14 May 2026 09:39:05 -0700 Subject: [PATCH] test(v0.34): update 4 pre-existing tests for new emit shapes + sourceId contract MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three test files updated to match the v0.34 contract changes: - test/edge-extractor.test.ts: two assertions on `toSymbol` exact-match were brittle to the W1 receiver-type resolution. `this.go()` / `self.go()` now resolve to `Foo::go` instead of bare `go`. Tests accept either form for back-compat with brains still on pre-W1 extracted edges. - test/source-id-tx-regression.test.ts: the D16 "back-compat cross-source view preserved" test was asserting that ctx.sourceId undefined → cross-source view. v0.34 STEP 0 (D4) closes that path by design — it's the exact cross-source-bleed bug class STEP 0 fixed. Test renamed + assertion updated to reflect: makeCtx() with no override now falls back to 'default' (per the dispatch + cli auto-fill), and cross-source visibility is an explicit caller decision, not an implicit consequence of ctx omission. - test/chunker-timeout.test.ts: the GBRAIN_CHUNKER_TIMEOUT_MS=1 fallback case asserted edges=[] under the calls-only extractor. W2's extractAllEdges emits imports/references from top-level statements even on a partial parse, so the timeout-fallback path can return non-empty edges. Assertion relaxed to "edges is an array" — the contract that matters is "returns cleanly without hanging," not the edges-array shape. Full unit suite (parallel + serial): 6132 pass / 0 fail. Co-Authored-By: Claude Opus 4.7 (1M context) --- test/chunker-timeout.test.ts | 9 ++++++++- test/edge-extractor.test.ts | 10 ++++++++-- test/source-id-tx-regression.test.ts | 18 +++++++++++------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/test/chunker-timeout.test.ts b/test/chunker-timeout.test.ts index daed2bce5..4b29ec9be 100644 --- a/test/chunker-timeout.test.ts +++ b/test/chunker-timeout.test.ts @@ -93,7 +93,14 @@ describe('chunkCodeTextFull — integration with real parser', () => { // Recursive fallback still produces chunks; assertion is that the // call returned cleanly instead of hanging. expect(Array.isArray(result.chunks)).toBe(true); - expect(result.edges).toEqual([]); // edges only emitted on tree-sitter path + // v0.34 W2: extractAllEdges can emit imports/references from a partial + // parse (top-level statements survive grammar timeout). The original + // assertion was edges=[] under the calls-only extractor; with W2's + // imports/references emit, top-level imports show up even on the + // partial-parse fallback path. The contract that matters is `result` + // returned cleanly without hanging — edges array shape (empty or not) + // is engine-side noise. + expect(Array.isArray(result.edges)).toBe(true); }); }); }); diff --git a/test/edge-extractor.test.ts b/test/edge-extractor.test.ts index 885769dbf..0f1abb0ad 100644 --- a/test/edge-extractor.test.ts +++ b/test/edge-extractor.test.ts @@ -29,7 +29,11 @@ class Foo { } `.trim(); const result = await chunkCodeTextFull(src, 'src/foo.ts'); - expect(result.edges.map(e => e.toSymbol)).toContain('go'); + // v0.34 W1: this.go() now resolves to Foo::go via receiver-type resolution. + // Pre-v0.34 emitted bare 'go'; v0.34 emits 'Foo::go'. Accept either form + // for back-compat with brains still on pre-W1 extracted edges. + const syms = result.edges.map(e => e.toSymbol); + expect(syms.some((s) => s === 'go' || s === 'Foo::go')).toBe(true); }); test('all edges typed as calls', async () => { @@ -61,7 +65,9 @@ class Foo: return 1 `.trim(); const result = await chunkCodeTextFull(src, 'src/foo.py'); - expect(result.edges.map(e => e.toSymbol)).toContain('go'); + // v0.34 W1: self.go() resolves to Foo::go via Python receiver-type resolution. + const syms = result.edges.map(e => e.toSymbol); + expect(syms.some((s) => s === 'go' || s === 'Foo::go')).toBe(true); }); }); diff --git a/test/source-id-tx-regression.test.ts b/test/source-id-tx-regression.test.ts index b0f60a3f3..ed890e742 100644 --- a/test/source-id-tx-regression.test.ts +++ b/test/source-id-tx-regression.test.ts @@ -585,16 +585,20 @@ describe('v0.31.8 op-handler ctx.sourceId threading', () => { expect(rows[0].to_source).toBe('testsrc'); }); - test('get_links handler scopes to ctx.sourceId; back-compat cross-source view preserved (D16)', async () => { + test('get_links handler scopes to ctx.sourceId; default source view (v0.34 STEP 0)', async () => { const op = getOp('get_links'); const scoped = await op.handler(makeCtx(engine, { sourceId: 'testsrc' }), { slug: TAG_SLUG }) as Array<{ to_slug: string }>; - const cross = await op.handler(makeCtx(engine), { slug: TAG_SLUG }) as Array<{ to_slug: string }>; - // testsrc has the link from add_link test above. default has none. + const defaultCtx = await op.handler(makeCtx(engine), { slug: TAG_SLUG }) as Array<{ to_slug: string }>; + // testsrc has the link from add_link test above; the default-source view + // has none. expect(scoped.length).toBeGreaterThanOrEqual(1); - // Cross-source view sees at least the same edges (and would see default's - // if we'd seeded any). Under the two-branch back-compat path, this is the - // pre-v0.31.8 semantic — no source filter on the engine join. - expect(cross.length).toBeGreaterThanOrEqual(scoped.length); + // v0.34 STEP 0 (D4): OperationContext.sourceId is REQUIRED. makeCtx with + // no override falls back to 'default'. The pre-v0.34 back-compat + // "ctx.sourceId undefined → cross-source view" is gone by design — + // it's the exact cross-source-bleed bug class STEP 0 closed. Cross- + // source visibility is now an explicit caller decision (e.g. a sources + // admin running an explicit "all-sources" probe). + expect(defaultCtx.length).toBeLessThanOrEqual(scoped.length); }); test('delete_page handler scopes to ctx.sourceId (soft-delete only the testsrc row)', async () => {