diff --git a/src/javascript/analysis/JavaScriptSourceAnalysis.ts b/src/javascript/analysis/JavaScriptSourceAnalysis.ts index 3ba38efd58..a2eb38647a 100644 --- a/src/javascript/analysis/JavaScriptSourceAnalysis.ts +++ b/src/javascript/analysis/JavaScriptSourceAnalysis.ts @@ -1,4 +1,7 @@ -import { DEFAULT_JAVASCRIPT_MEMBER_MUTATION_ALLOWANCE } from "../../domain/javascript/javascriptSemanticWorkAllowance.js"; +import { + DEFAULT_JAVASCRIPT_MEMBER_MUTATION_ALLOWANCE, + isJavaScriptMemberMutationRefusal, +} from "../../domain/javascript/javascriptSemanticWorkAllowance.js"; import { resolveJavaScriptSemanticPrecision } from "../../domain/javascript/javascriptSemanticPrecision.js"; import type { JavaScriptSourceAnalysisLimits, @@ -179,8 +182,21 @@ class ScopeJavaScriptSourceAnalysis implements JavaScriptSourceAnalysisPort { analyze( ...args: Parameters ): ReturnType { + const purpose = args[5]; return this.worker.analyze(...args).then((result) => { - if (!result.ok) this.#failed = true; + // Preload discovery skips a source whose member-mutation allowance the + // worker refused and reported; the normal pass recomputes and reports + // it. That refusal leaves the process healthy, so the worker can still + // park and keep the static checkpoints discovery retained. canReuse + // still checks the process before parking. + if ( + !result.ok && + !( + purpose === "preload-discovery" && + isJavaScriptMemberMutationRefusal(result.error.error) + ) + ) + this.#failed = true; return result; }); } diff --git a/tests/boundary/javascript/javascriptSourceAnalysisWorker.test.ts b/tests/boundary/javascript/javascriptSourceAnalysisWorker.test.ts index faa3b52d5c..ab2640e79c 100644 --- a/tests/boundary/javascript/javascriptSourceAnalysisWorker.test.ts +++ b/tests/boundary/javascript/javascriptSourceAnalysisWorker.test.ts @@ -1003,3 +1003,85 @@ it("keeps wrapped route ancestry, navigation and unknown named parents in the re await worker.close(); } }); + +it.each([ + ["preload-discovery", 1], + ["analysis", 2], +] as const)( + "after a %s member-mutation refusal, the next checkout uses %i launch(es)", + async (purpose, expectedLaunches) => { + const scope = new ArtifactResourceScope(); + const launches: number[] = []; + const launcher: typeof spawnOwnedProviderProcess = async (request) => { + const spawned = await spawnOwnedProviderProcess(request); + if (spawned.process.pid !== undefined) launches.push(spawned.process.pid); + return spawned; + }; + const limits = { + heapMb: 128, + timeoutMs: 30_000, + memberMutationAllowance: { aliasStates: 8, source: "runtime" } as const, + }; + // Four conditional self-selections before one member write (#8294). + const refused = source( + "refused.js", + [ + "function probe(input, env) { var m; if (env.first) m = env.first.info;", + ...Array.from( + { length: 4 }, + (_, index) => + `if (/case${String(index)}/.test(input)) m = m[${String(index % 2)}];`, + ), + "m[1] = input.length; return m; } module.exports = probe;", + ].join(" "), + ); + const accepted = source("accepted.js", "module.exports = 1;"); + try { + const first = await createJavaScriptSourceAnalysis(limits, 2, { + scope, + launcher, + }); + try { + const capacity = { nodes: 0, unknowns: 0 }; + const refusal = await first.analyze( + refused, + capacity, + undefined, + undefined, + "commonjs", + purpose, + ); + expect(refusal.ok).toBe(false); + const success = await first.analyze( + accepted, + capacity, + undefined, + undefined, + "commonjs", + purpose, + ); + if (!success.ok) throw success.error.error; + } finally { + await first.close(); + } + // Discovery's refused source is analyzed again by the normal pass, so + // only discovery parks its healthy worker; other failures still close it. + const next = await createJavaScriptSourceAnalysis(limits, 1, { + scope, + launcher, + }); + try { + const result = await next.analyze(accepted, { + nodes: 100, + unknowns: 100, + }); + if (!result.ok) throw result.error.error; + } finally { + await next.close(); + } + expect(launches).toHaveLength(expectedLaunches); + } finally { + await scope.close(); + } + }, +);