Skip to content

Find code by asking what it does. A CLI for coding agents that uses Jev to discover relevant files and source context.

Revalidate buffered source before uploads and final output

David Zhang92ca7f993d51
diff --git a/packages/core/src/gateway.ts b/packages/core/src/gateway.ts
index 9dd3a24..419130b 100644
--- a/packages/core/src/gateway.ts
+++ b/packages/core/src/gateway.ts
@@ -9,7 +9,12 @@ export type EvaluationRequest = {
export class EvaluationFailure extends Error {
constructor(
- public readonly kind: "authentication" | "request-limit" | "provider" | "cancelled",
+ public readonly kind:
+ | "authentication"
+ | "request-limit"
+ | "provider"
+ | "cancelled"
+ | "source-invalid",
public readonly splitEligible = false,
) {
super(`Jev evaluation failed: ${kind}`);
@@ -70,7 +75,7 @@ export function createEvaluator(options: {
},
async evaluate(
request: EvaluationRequest,
- policy?: { navigation?: boolean },
+ policy?: { navigation?: boolean; beforeAttempt?: () => Promise<void> },
): Promise<Record<string, number>> {
assertActive();
const cacheInput: CacheInput = {
@@ -112,6 +117,8 @@ export function createEvaluator(options: {
throw new EvaluationFailure("cancelled");
}
}
+ await policy?.beforeAttempt?.();
+ assertActive();
try {
const result = await evaluate({
model: gateway.evaluationModel("typesafe-ai/jev"),
diff --git a/packages/core/src/retrieve.ts b/packages/core/src/retrieve.ts
index 1441a6a..c14dd83 100644
--- a/packages/core/src/retrieve.ts
+++ b/packages/core/src/retrieve.ts
@@ -1,6 +1,6 @@
import { basename, extname } from "node:path";
import { createFilesystem, type Snapshot, type DirectoryEntry } from "./filesystem";
-import { EvaluationFailure } from "./gateway";
+import { type EvaluationRequest, EvaluationFailure } from "./gateway";
import { inspect, pythonPreview, sourceForUnit, splitSource } from "./source";
import {
navigationRequest,
@@ -30,6 +30,32 @@ export async function retrieve(input: SearchInput, evaluator: Evaluator): Promis
const visited = new Set<string>();
const pruned = new Map<string, NavigationItem>();
const previews = new Map<string, FilePreview>();
+ type Donor = { path: string; contentHash: string };
+ const donors = new WeakMap<NavigationItem, Donor[]>();
+ const anchors = new WeakMap<{ path: string; classes: string[] }, Donor>();
+ function buffered(item: NavigationItem, sources: Donor[]) {
+ donors.set(
+ item,
+ sources.map(({ path, contentHash }) => ({ path, contentHash })),
+ );
+ return item;
+ }
+ let validationQueue: Promise<void> = Promise.resolve();
+ async function freshEvaluation(request: EvaluationRequest, sources: Donor[], navigation = false) {
+ const validate = async () => {
+ for (const source of new Map(sources.map((source) => [source.path, source])).values()) {
+ if (!(await unchanged(source))) throw new EvaluationFailure("source-invalid");
+ }
+ };
+ const beforeAttempt = () => {
+ const pending = validationQueue.then(validate);
+ validationQueue = pending.catch(() => {});
+ return pending;
+ };
+ // Preserve queued request order while checks perform I/O; provider work stays concurrent.
+ await beforeAttempt();
+ return evaluator.evaluate(request, { navigation, beforeAttempt });
+ }
let entriesSeen = 0;
let stop = false;
function issue(kind: string, count = 1) {
@@ -72,20 +98,24 @@ export async function retrieve(input: SearchInput, evaluator: Evaluator): Promis
if (batch.length) batches.push(batch);
async function scoreGroup(group: NavigationItem[]) {
try {
- const scores = await evaluator.evaluate(navigationRequest(input.query, group, anchor), {
- navigation: true,
- });
+ const sources = group.flatMap((item) => donors.get(item) ?? []);
+ if (anchor) sources.push(anchors.get(anchor)!);
+ const scores = await freshEvaluation(
+ navigationRequest(input.query, group, anchor),
+ sources,
+ true,
+ );
group.forEach((item, index) => results.push({ item, score: scores[`q${index}`]! }));
} catch (error) {
if (
error instanceof EvaluationFailure &&
- error.kind === "provider" &&
- error.splitEligible &&
+ (error.kind === "source-invalid" || (error.kind === "provider" && error.splitEligible)) &&
group.length > 1
) {
const middle = Math.ceil(group.length / 2);
batches.push(group.slice(0, middle), group.slice(middle));
- } else issue(error instanceof EvaluationFailure ? error.kind : "provider");
+ } else if (!(error instanceof EvaluationFailure && error.kind === "source-invalid"))
+ issue(error instanceof EvaluationFailure ? error.kind : "provider");
}
}
// Failed groups append their halves to the same queue. A recovered parent is
@@ -161,12 +191,14 @@ export async function retrieve(input: SearchInput, evaluator: Evaluator): Promis
...item.childPreview!,
contentSamples: [] as NonNullable<DirectoryPreview["contentSamples"]>,
};
+ const sources: Donor[] = [];
const children = preview.entries.filter((child) => child.kind === "file");
const perFile = Math.max(80, Math.floor(16000 / Math.max(1, children.length)));
for (const child of children) {
if (stop) break;
const snapshotValue = await snapshot(`${item.path}/${child.name}`);
if (!snapshotValue || Buffer.byteLength(snapshotValue.source) > 1_000_000) continue;
+ sources.push({ path: snapshotValue.path, contentHash: snapshotValue.contentHash });
const source = snapshotValue.source;
const part = Math.floor(perFile / 3);
const offsets = [
@@ -197,7 +229,7 @@ export async function retrieve(input: SearchInput, evaluator: Evaluator): Promis
sample.truncated = true;
}
}
- return { ...item, childPreview: preview };
+ return buffered({ ...item, childPreview: preview }, sources);
}
async function previewFile(source: Snapshot): Promise<FilePreview> {
const bytes = Buffer.from(source.source);
@@ -309,24 +341,29 @@ export async function retrieve(input: SearchInput, evaluator: Evaluator): Promis
previews.set(entry.path, filePreview);
if (Buffer.byteLength(source.source) > 1_000_000) {
issue("resource_limit");
- items.push({ path: entry.path, kind: "file", filePreview });
+ items.push(buffered({ path: entry.path, kind: "file", filePreview }, [source]));
continue;
}
const chunks = splitSource(source, 12_000);
for (const chunk of chunks) {
const text = sourceForUnit(source, chunk);
- items.push({
- path: entry.path,
- kind: "file",
- filePreview: {
- sizeBytes: Buffer.byteLength(source.source),
- extension: extname(entry.path),
- text,
- previewBytes: Buffer.byteLength(text),
- truncated: chunks.length > 1,
- range: "sampled source ranges",
- },
- });
+ items.push(
+ buffered(
+ {
+ path: entry.path,
+ kind: "file",
+ filePreview: {
+ sizeBytes: Buffer.byteLength(source.source),
+ extension: extname(entry.path),
+ text,
+ previewBytes: Buffer.byteLength(text),
+ truncated: chunks.length > 1,
+ range: "sampled source ranges",
+ },
+ },
+ [source],
+ ),
+ );
}
}
}
@@ -414,6 +451,7 @@ export async function retrieve(input: SearchInput, evaluator: Evaluator): Promis
];
if (classes.length && Buffer.byteLength(JSON.stringify(classes)) < 4000) {
anchor = { path: candidate.path, classes };
+ anchors.set(anchor, candidate);
break;
}
}
@@ -453,7 +491,18 @@ export async function retrieve(input: SearchInput, evaluator: Evaluator): Promis
source,
input.query,
candidate.score,
- evaluator,
+ {
+ get requests() {
+ return evaluator.requests;
+ },
+ evaluate: (request) => {
+ const context = request.state as { selectedEvidence?: Evidence[] };
+ return freshEvaluation(request, [
+ candidate,
+ ...(context.selectedEvidence ?? []).map((entry) => candidates.get(entry.path)!),
+ ]);
+ },
+ },
async () => {
if (input.signal.aborted) throw new EvaluationFailure("cancelled");
const current = await unchanged(candidate);
@@ -466,7 +515,8 @@ export async function retrieve(input: SearchInput, evaluator: Evaluator): Promis
);
files.set(candidate.path, selection.file);
declarations.set(candidate.path, selection.declarations);
- for (const entry of selection.issues) issue(entry.kind, entry.count);
+ for (const entry of selection.issues)
+ if (entry.kind !== "source-invalid") issue(entry.kind, entry.count);
});
await select();
const evidence: Evidence[] = [];
@@ -501,14 +551,15 @@ export async function retrieve(input: SearchInput, evaluator: Evaluator): Promis
if (!source) return;
const preview = previews.get(candidate.path)!;
try {
- const scores = await evaluator.evaluate(
- roleRequest(input.query, candidate.path, preview),
- );
+ const scores = await freshEvaluation(roleRequest(input.query, candidate.path, preview), [
+ candidate,
+ ]);
files.get(candidate.path)!.roles = Object.keys(scores).filter(
(role) => scores[role]! > 0.5,
);
} catch (error) {
- issue(error instanceof EvaluationFailure ? error.kind : "provider");
+ if (!(error instanceof EvaluationFailure && error.kind === "source-invalid"))
+ issue(error instanceof EvaluationFailure ? error.kind : "provider");
}
});
if (issues.has("authentication") && !files.size)
@@ -539,6 +590,8 @@ export async function retrieve(input: SearchInput, evaluator: Evaluator): Promis
declarations,
(path) => unchanged(candidates.get(path)!),
);
+ // Role evaluation may outlive the bytes it classified, for every language.
+ for (const candidate of candidates.values()) await unchanged(candidate);
return {
root: reader.root,
query: input.query,
diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts
index 57f4219..bbd14ab 100644
--- a/packages/core/src/types.ts
+++ b/packages/core/src/types.ts
@@ -53,6 +53,6 @@ export type Evaluator = {
readonly cacheIssues?: Array<{ kind: string; count: number }>;
evaluate(
request: EvaluationRequest,
- policy?: { navigation?: boolean },
+ policy?: { navigation?: boolean; beforeAttempt?: () => Promise<void> },
): Promise<Record<string, number>>;
};
diff --git a/scripts/test-suite.sh b/scripts/test-suite.sh
index cb68870..890bcbd 100644
--- a/scripts/test-suite.sh
+++ b/scripts/test-suite.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
-bun test apps/cli/test packages/core/test test/reference test/gateway.test.ts test/retrieval.test.ts
+bun test apps/cli/test packages/core/test test/reference test/gateway.test.ts test/retrieval.test.ts test/retrieval-freshness.test.ts
node --experimental-strip-types --test test/parser/*.test.ts
node --test test/release.test.mjs
python3 -B -m unittest discover -s evals/implementation/swebench -p test_installed.py
diff --git a/test/installed.test.mjs b/test/installed.test.mjs
index 10bde81..b8dab1d 100644
--- a/test/installed.test.mjs
+++ b/test/installed.test.mjs
@@ -116,6 +116,7 @@ async function context(t, mode = "healthy", executable = binary) {
}
assert.ok(requests.length < 256, "Synthetic search stopped making bounded forward progress");
requests.push({ body, raw, receivedAt: performance.now() });
+ if (typeof mode === "function" && (await mode({ body, raw, tree, response }))) return;
if (mode === "rate-limit" && requests.length === 1) {
response.writeHead(429, { "content-type": "application/json", "retry-after": "1" });
response.end(JSON.stringify({ error: "fixture rate limit" }));
@@ -724,3 +725,78 @@ test("missing or corrupt packaged Python assets fail closed without downloads",
await rm(copy, { recursive: true, force: true });
}
});
+
+for (const mutation of ["changed", "ignored"])
+ test(`installed final freshness discards ${mutation} source after role evaluation`, async (t) => {
+ let sawRole = false;
+ const fixture = await context(t, async ({ body, tree, response }) => {
+ if (body.questions.implementation) {
+ sawRole = true;
+ await writeFile(
+ join(tree, mutation === "ignored" ? ".ignore" : "a.ts"),
+ mutation === "ignored" ? "a.ts\n" : "export function replacement() { return 2; }\n",
+ );
+ }
+ response.writeHead(200, { "content-type": "application/json" });
+ response.end(
+ JSON.stringify({
+ answers: Object.fromEntries(
+ Object.keys(body.questions).map((id) => [id, { type: "boolean", probability: 0.9 }]),
+ ),
+ }),
+ );
+ return true;
+ });
+ await rm(fixture.tree, { recursive: true });
+ await mkdir(fixture.tree);
+ await writeFile(
+ join(fixture.tree, "a.ts"),
+ 'export function selected() { return "FINAL_STALE_SENTINEL"; }\n',
+ );
+ const result = await fixture.run([query, fixture.tree, "--no-cache"]);
+ assert.ok(sawRole);
+ assert.equal(result.code, 2, result.stdout);
+ assert.match(result.stdout, /incomplete/);
+ assert.match(result.stdout, /a\.ts/);
+ assert.ok(!result.stdout.includes("FINAL_STALE_SENTINEL"));
+ assert.ok(!result.stdout.includes('Source block "a.ts"'));
+ });
+
+test("installed queued freshness withholds excluded source uploads", async (t) => {
+ let uploads = 0;
+ const releases = [];
+ const fixture = await context(t, async ({ body, raw, tree, response }) => {
+ if (raw.includes("QUEUED_INSTALLED_SENTINEL")) {
+ uploads++;
+ if (uploads <= 8)
+ await new Promise((resolve) => {
+ releases.push(resolve);
+ if (releases.length === 8)
+ void writeFile(join(tree, ".ignore"), "large.txt\n").then(() =>
+ releases.forEach((release) => release()),
+ );
+ });
+ }
+ response.writeHead(200, { "content-type": "application/json" });
+ response.end(
+ JSON.stringify({
+ answers: Object.fromEntries(
+ Object.keys(body.questions).map((id) => [id, { type: "boolean", probability: 0.1 }]),
+ ),
+ }),
+ );
+ return true;
+ });
+ t.after(() => releases.forEach((release) => release()));
+ await rm(fixture.tree, { recursive: true });
+ await mkdir(fixture.tree);
+ await writeFile(
+ join(fixture.tree, "large.txt"),
+ "QUEUED_INSTALLED_SENTINEL line\n".repeat(18000),
+ );
+ const result = await fixture.run([query, fixture.tree, "--no-cache"]);
+ assert.equal(uploads, 8);
+ assert.equal(result.code, 2, result.stdout);
+ assert.match(result.stdout, /incomplete/);
+ assert.ok(!result.stdout.includes("QUEUED_INSTALLED_SENTINEL"));
+});
diff --git a/test/retrieval-freshness.test.ts b/test/retrieval-freshness.test.ts
new file mode 100644
index 0000000..aa3a626
--- /dev/null
+++ b/test/retrieval-freshness.test.ts
@@ -0,0 +1,340 @@
+import { expect } from "bun:test";
+import { mkdtemp, mkdir, writeFile, rm } from "node:fs/promises";
+import { join } from "node:path";
+import { tmpdir } from "node:os";
+import { testIfDocker } from "./helpers/docker";
+import { retrieve } from "../packages/core/src/retrieve";
+import { createEvaluator } from "../packages/core/src/gateway";
+
+testIfDocker(
+ "queued navigation never uploads source excluded after the first wave",
+ async () => {
+ const root = await mkdtemp(join(tmpdir(), "jg-queued-freshness-"));
+ const releases: Array<() => void> = [];
+ let uploads = 0;
+ const server = Bun.serve({
+ port: 0,
+ async fetch(request) {
+ const body = (await request.json()) as any;
+ if (JSON.stringify(body).includes("QUEUED_SENTINEL")) {
+ uploads++;
+ if (uploads <= 8)
+ await new Promise<void>((resolve) => {
+ releases.push(resolve);
+ if (releases.length === 8)
+ void writeFile(join(root, ".ignore"), "large.txt\n").then(() =>
+ releases.forEach((release) => release()),
+ );
+ });
+ }
+ return Response.json({
+ answers: Object.fromEntries(
+ Object.keys(body.questions).map((id) => [id, { type: "boolean", probability: 0.1 }]),
+ ),
+ });
+ },
+ });
+ try {
+ await writeFile(join(root, "large.txt"), "QUEUED_SENTINEL line\n".repeat(26000));
+ const signal = new AbortController().signal;
+ const result = await retrieve(
+ { root, query: "sentinel", signal },
+ createEvaluator({ apiKey: "fixture", baseURL: `http://127.0.0.1:${server.port}`, signal }),
+ );
+ expect(uploads).toBe(8);
+ expect(result.status).toBe("incomplete");
+ } finally {
+ releases.forEach((release) => release());
+ server.stop(true);
+ await rm(root, { recursive: true, force: true });
+ }
+ },
+ 120_000,
+);
+
+for (const mutation of ["ignored", "changed"] as const)
+ testIfDocker(
+ `final excerpts are invalidated when ${mutation} during role evaluation`,
+ async () => {
+ const root = await mkdtemp(join(tmpdir(), "jg-final-freshness-"));
+ let role = false;
+ const server = Bun.serve({
+ port: 0,
+ async fetch(request) {
+ const body = (await request.json()) as any;
+ if (body.questions.implementation) {
+ role = true;
+ await writeFile(
+ join(root, mutation === "ignored" ? ".ignore" : "a.ts"),
+ mutation === "ignored" ? "a.ts\n" : "export function replaced() { return 2; }\n",
+ );
+ }
+ return Response.json({
+ answers: Object.fromEntries(
+ Object.keys(body.questions).map((id) => [id, { type: "boolean", probability: 0.9 }]),
+ ),
+ });
+ },
+ });
+ try {
+ await writeFile(
+ join(root, "a.ts"),
+ 'export function selected() { return "STALE_SENTINEL"; }\n',
+ );
+ const signal = new AbortController().signal;
+ const result = await retrieve(
+ { root, query: "selected", signal },
+ createEvaluator({
+ apiKey: "fixture",
+ baseURL: `http://127.0.0.1:${server.port}`,
+ signal,
+ }),
+ );
+ expect(role).toBe(true);
+ expect(result.status).toBe("incomplete");
+ expect(result.files[0]?.excerpts).toEqual([]);
+ expect(result.files[0]?.sourceOmitted).toBe(true);
+ } finally {
+ server.stop(true);
+ await rm(root, { recursive: true, force: true });
+ }
+ },
+ 120_000,
+ );
+
+testIfDocker(
+ "navigation HTTP retry revalidates its buffered source",
+ async () => {
+ const root = await mkdtemp(join(tmpdir(), "jg-retry-freshness-"));
+ let uploads = 0;
+ const server = Bun.serve({
+ port: 0,
+ async fetch(request) {
+ const body = (await request.json()) as any;
+ if (JSON.stringify(body).includes("RETRY_SENTINEL")) {
+ uploads++;
+ await writeFile(join(root, ".ignore"), "a.txt\n");
+ return Response.json({ error: "temporary unavailable" }, { status: 503 });
+ }
+ throw new Error("Unexpected request");
+ },
+ });
+ try {
+ await writeFile(join(root, "a.txt"), "RETRY_SENTINEL\n");
+ const signal = new AbortController().signal;
+ const result = await retrieve(
+ { root, query: "retry", signal },
+ createEvaluator({ apiKey: "fixture", baseURL: `http://127.0.0.1:${server.port}`, signal }),
+ );
+ expect(uploads).toBe(1);
+ expect(result.status).toBe("incomplete");
+ } finally {
+ server.stop(true);
+ await rm(root, { recursive: true, force: true });
+ }
+ },
+ 120_000,
+);
+
+for (const phase of ["selection", "role"] as const)
+ testIfDocker(
+ `${phase} HTTP retries withhold newly excluded source`,
+ async () => {
+ const root = await mkdtemp(join(tmpdir(), "jg-phase-retry-"));
+ let uploads = 0;
+ const server = Bun.serve({
+ port: 0,
+ async fetch(request) {
+ const body = (await request.json()) as any;
+ const targeted =
+ phase === "role" ? !!body.questions.implementation : !!body.state.declarations;
+ if (targeted) {
+ uploads++;
+ await writeFile(join(root, ".ignore"), "a.ts\n");
+ return Response.json({ error: "temporary unavailable" }, { status: 503 });
+ }
+ return Response.json({
+ answers: Object.fromEntries(
+ Object.keys(body.questions).map((id) => [id, { type: "boolean", probability: 0.9 }]),
+ ),
+ });
+ },
+ });
+ try {
+ await writeFile(
+ join(root, "a.ts"),
+ 'export function selected() { return "PHASE_SENTINEL"; }\n',
+ );
+ const signal = new AbortController().signal;
+ const result = await retrieve(
+ { root, query: "selected", signal },
+ createEvaluator({
+ apiKey: "fixture",
+ baseURL: `http://127.0.0.1:${server.port}`,
+ signal,
+ }),
+ );
+ expect(uploads).toBe(1);
+ expect(result.status).toBe("incomplete");
+ expect(result.files[0]?.excerpts).toEqual([]);
+ } finally {
+ server.stop(true);
+ await rm(root, { recursive: true, force: true });
+ }
+ },
+ 120_000,
+ );
+
+for (const size of [2, 4])
+ testIfDocker(
+ `split navigation retries retain healthy donors from ${size} items`,
+ async () => {
+ const root = await mkdtemp(join(tmpdir(), "jg-split-freshness-"));
+ const uploads: string[][] = [];
+ const server = Bun.serve({
+ port: 0,
+ async fetch(request) {
+ const body = (await request.json()) as any;
+ uploads.push(body.state.items.map((item: any) => item.path));
+ if (uploads.length === 1) {
+ await writeFile(join(root, ".ignore"), "a.txt\n");
+ return Response.json({ error: "temporary unavailable" }, { status: 503 });
+ }
+ return Response.json({
+ answers: Object.fromEntries(
+ Object.keys(body.questions).map((id) => [id, { type: "boolean", probability: 0.1 }]),
+ ),
+ });
+ },
+ });
+ try {
+ await writeFile(join(root, "a.txt"), "EXCLUDED_SPLIT_SENTINEL\n");
+ for (const name of ["b.txt", "c.txt", "d.txt"].slice(0, size - 1))
+ await writeFile(join(root, name), "healthy source\n");
+ const signal = new AbortController().signal;
+ const result = await retrieve(
+ { root, query: "selected", signal },
+ createEvaluator({
+ apiKey: "fixture",
+ baseURL: `http://127.0.0.1:${server.port}`,
+ signal,
+ }),
+ );
+ expect(uploads).toEqual(
+ size === 2
+ ? [["a.txt", "b.txt"], ["b.txt"]]
+ : [["a.txt", "b.txt", "c.txt", "d.txt"], ["c.txt", "d.txt"], ["b.txt"]],
+ );
+ expect(result.status).toBe("incomplete");
+ } finally {
+ server.stop(true);
+ await rm(root, { recursive: true, force: true });
+ }
+ },
+ 120_000,
+ );
+
+for (const donor of ["sample", "anchor"] as const)
+ testIfDocker(
+ `relationship retry revalidates its ${donor} donor`,
+ async () => {
+ const root = await mkdtemp(join(tmpdir(), "jg-relation-freshness-"));
+ let relationships = 0;
+ const server = Bun.serve({
+ port: 0,
+ async fetch(request) {
+ const body = (await request.json()) as any;
+ if (body.state.relationAnchor) {
+ relationships++;
+ expect(JSON.stringify(body)).toContain("RELATION_SENTINEL");
+ await writeFile(
+ join(root, ".ignore"),
+ donor === "sample" ? "deep/nested/sample.ts\n" : "anchor.ts\n",
+ );
+ return Response.json({ error: "temporary unavailable" }, { status: 503 });
+ }
+ return Response.json({
+ answers: Object.fromEntries(
+ Object.keys(body.questions).map((id, index) => [
+ id,
+ {
+ type: "boolean",
+ probability: body.state.items?.[index]?.kind === "file" ? 0.9 : 0.1,
+ },
+ ]),
+ ),
+ });
+ },
+ });
+ try {
+ await mkdir(join(root, "deep/nested"), { recursive: true });
+ await writeFile(
+ join(root, "anchor.ts"),
+ "export class Anchor {\n method() { return 1; }\n}\n",
+ );
+ await writeFile(
+ join(root, "deep/nested/sample.ts"),
+ 'export class Child extends Anchor { method() { return "RELATION_SENTINEL"; } }\n',
+ );
+ const signal = new AbortController().signal;
+ const result = await retrieve(
+ { root, query: "selected", signal },
+ createEvaluator({
+ apiKey: "fixture",
+ baseURL: `http://127.0.0.1:${server.port}`,
+ signal,
+ }),
+ );
+ expect(relationships).toBe(1);
+ expect(result.status).toBe("incomplete");
+ } finally {
+ server.stop(true);
+ await rm(root, { recursive: true, force: true });
+ }
+ },
+ 120_000,
+ );
+
+testIfDocker(
+ "additional-selection HTTP retry revalidates cross-file evidence donors",
+ async () => {
+ const root = await mkdtemp(join(tmpdir(), "jg-evidence-retry-"));
+ let attempts = 0;
+ const server = Bun.serve({
+ port: 0,
+ async fetch(request) {
+ const body = (await request.json()) as any;
+ if (
+ body.state.path === "b.ts" &&
+ body.state.selectedEvidence?.some((entry: any) => entry.path === "a.ts")
+ ) {
+ attempts++;
+ await writeFile(join(root, ".ignore"), "a.ts\n");
+ return Response.json({ error: "temporary unavailable" }, { status: 503 });
+ }
+ return Response.json({
+ answers: Object.fromEntries(
+ Object.keys(body.questions).map((id) => [id, { type: "boolean", probability: 0.9 }]),
+ ),
+ });
+ },
+ });
+ try {
+ await writeFile(join(root, "a.ts"), 'export function first() { return "DONOR_SENTINEL"; }\n');
+ await writeFile(join(root, "b.ts"), "export function second() { return first(); }\n");
+ const signal = new AbortController().signal;
+ const result = await retrieve(
+ { root, query: "selected", signal },
+ createEvaluator({ apiKey: "fixture", baseURL: `http://127.0.0.1:${server.port}`, signal }),
+ );
+ expect(attempts).toBe(1);
+ expect(result.status).toBe("incomplete");
+ expect(result.files.find((file) => file.path === "a.ts")?.excerpts).toEqual([]);
+ expect(result.files.find((file) => file.path === "b.ts")?.excerpts.length).toBeGreaterThan(0);
+ } finally {
+ server.stop(true);
+ await rm(root, { recursive: true, force: true });
+ }
+ },
+ 120_000,
+);