From 804215515bc1b648d04ac1b89fe6818ca3780146 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 06:46:34 +0000 Subject: [PATCH 1/3] fix(pm): mkdtempSync completeness fails tests and tooling, reports shipped package source The directory-creating sweep's completeness rule now judges an UNRESOLVED mkdtempSync site by its file population: a test file or repo tooling still fails, a non-test file under a workspace package's src/ is reported and not failed, because its base is the user's run-time choice (ruling record 7075362923). One predicate, isShippedPackageSource, reusing the runner-env gate's product-source test and the workspace enumerator; fast-tier pins on the spelling that redded main, each with a control one step away. The header's stale measurement is refreshed from the scan's own exports. Claude-Session: https://claude.ai/code/session_01QsR2jTeURPvEm465RcoYEC Co-authored-by: Claude --- scripts/pm/dispatch-gates.mjs | 64 +++++++++++++++++-- scripts/pm/dispatch-gates.self-test.mjs | 84 +++++++++++++++++++++++-- 2 files changed, 136 insertions(+), 12 deletions(-) diff --git a/scripts/pm/dispatch-gates.mjs b/scripts/pm/dispatch-gates.mjs index 7c13f4d4001..598d447ffea 100644 --- a/scripts/pm/dispatch-gates.mjs +++ b/scripts/pm/dispatch-gates.mjs @@ -8713,13 +8713,22 @@ export function trackedPrefixes(files) { // absolute literal — is outside the tree by construction. So the classifier has // THREE answers, and the third carries the honesty: a site whose base it cannot // resolve is UNRESOLVED, never "probably fine". For `mkdtempSync` — the shape -// every in-tree fixture in this tree is built from — an unresolved site is a -// FAILURE. A detector that silently skipped what it could not read would be -// this card's own defect one level up: green over the sites nobody measured. +// every in-tree fixture in this tree is built from — an unresolved site in a +// test file or in repo tooling is a FAILURE. A detector that silently skipped +// what it could not read would be this card's own defect one level up: green +// over the sites nobody measured. // -// Measured on the tree at the time of writing: 359 `mkdtempSync` sites — 4 in -// the tree (the four `packages/cli` fixtures the convention names), the rest in -// the system temp directory, 0 unresolved. +// The boundary of that rule is the FILE POPULATION: an unresolved site in +// shipped package source (a non-test file under a workspace package's `src/`, +// `isShippedPackageSource`) is REPORTED and not failed, because its base is +// chosen at run time by whoever runs the published code (ruling record +// 7075362923). +// +// Measured on 2026-11-22 at 3f7fdd00 through `scratchDirSitesInSource` and +// `isShippedPackageSource`: 1821 `mkdtempSync` sites — 1463 in `isTestFilePath` +// test files (47 in the tree), 344 in repo tooling and the other non-package +// sources (0 in the tree), 14 in shipped package source (all in the system +// temp directory); 0 unresolved in any population. // // `mkdirSync` is swept too and deliberately NOT held to completeness: of its // sites, ~124 take a base this resolver cannot see (a function parameter, a @@ -9992,6 +10001,49 @@ export function exposedScratchDirs({ cwd = ROOT, files = null } = {}) { return { ...sweep, exposed, covered }; } +/** + * ── Which UNRESOLVED `mkdtempSync` site fails completeness: the FILE ────────── + * + * In a test file or a repo script the base of a scratch directory is something + * this tree chose, so a base the scan cannot read is a gap in the reading and + * fails. Shipped package source is the population where that stops holding: a + * published command stages beside a directory its USER names at run time (a + * cwd-relative argument), and no reading of this tree can say whether that + * lands inside a checkout. Failing it forces a spelling that only hides the + * base, never a safer directory. So that population is reported and not + * failed (ruling record 7075362923, 「扫描只管仓内运行的代码」). + * + * The boundary is the site's FILE, never its resolution: "in the tree" is + * exactly what an unresolved site does not know. ⛔ Nor is it "not a test + * file" alone — repo tooling is code this checkout runs, and it stays held. + * + * Shipped package source = a non-test source under a workspace package's own + * `src/`. "Non-test" is the runner-env gate's `isProductSource` (a test by name + * or by directory, `.d.ts` excluded), the stricter of the tree's test + * predicates, so a helper under `src/__tests__/` stays held; "workspace + * package" is a workspace member holding a manifest, from the enumerator. + * Neither half is a list kept here. + */ +export function isShippedPackageSource(rel, packageDirs) { + return isRunnerEnvProductSource(rel) && packageDirs.some((dir) => rel.startsWith(`${dir}/src/`)); +} + +/** + * The completeness rule's verdict over a sweep's `unresolved` sites: `failing` + * is what reds the live case, `reported` the shipped-source remainder it names + * and does not fail. A `mkdirSync` site is in neither — that half was never + * held to completeness (the header above). + */ +export function mkdtempCompleteness(unresolved, { packageDirs = workspacePackageDirs(ROOT) } = {}) { + const failing = []; + const reported = []; + for (const site of unresolved) { + if (site.call !== 'mkdtempSync') continue; + (isShippedPackageSource(site.file, packageDirs) ? reported : failing).push(site); + } + return { failing, reported }; +} + /** An ignore file every clone has, as opposed to one local to whoever ran this. */ function isTrackedIgnoreSource(source) { if (!source) return false; diff --git a/scripts/pm/dispatch-gates.self-test.mjs b/scripts/pm/dispatch-gates.self-test.mjs index 6f25e740840..a8de9c527c4 100644 --- a/scripts/pm/dispatch-gates.self-test.mjs +++ b/scripts/pm/dispatch-gates.self-test.mjs @@ -185,6 +185,7 @@ import { isInRootTsProgram, isNonPathNamespace, isPlainTopLevelDir, + isShippedPackageSource, isTestFilePath, isTypeCheckInvocation, jobFilterOutputRefs, @@ -210,6 +211,7 @@ import { maskShellComments, metadataFormModulePaths, metadataFormsSurfaceIsExtracted, + mkdtempCompleteness, liveDerivationInputs, narrowToDerivationInputs, notRunnableCommandSet, @@ -11452,6 +11454,69 @@ export function selfTest({ tier = 'full' } = {}) { wrapperBodyScan, ); + // ── Which UNRESOLVED mkdtempSync site fails completeness: the FILE ───────── + // + // The live completeness case in the slow section below fails an unresolved + // mkdtempSync site in a test file or repo tooling, and REPORTS one in shipped + // package source, whose base the user names at run time (ruling record + // 7075362923). The boundary is pinned here, in the fast tier a pull request's + // lane runs, on the exact spelling that redded main: a staging directory + // beside a caller's directory. Each arm has a control one step away. + const callerDirSource = 'const staging = mkdtempSync(join(dir, SKILLS_STAGING_PREFIX));'; + const tmpdirSource = 'const staging = mkdtempSync(join(tmpdir(), SKILLS_STAGING_PREFIX));'; + const completenessPackages = ['packages/cli']; + const completenessOf = (rel, source = callerDirSource, packageDirs = completenessPackages) => + mkdtempCompleteness(scratchDirSitesInSource(rel, source).unresolved, { packageDirs }); + const verdictIs = (v, failing, reported) => v.failing.length === failing && v.reported.length === reported; + const shippedVerdict = completenessOf('packages/cli/src/utils/skills-install-state.ts'); + t( + "a caller's-directory mkdtempSync base in shipped package source is REPORTED, not failed", + verdictIs(shippedVerdict, 0, 1) && shippedVerdict.reported[0].file === 'packages/cli/src/utils/skills-install-state.ts', + shippedVerdict, + ); + t( + 'CONTROL: the same file in a directory that holds no workspace package still FAILS', + verdictIs(completenessOf('packages/cli/src/utils/skills-install-state.ts', callerDirSource, ['packages/core']), 1, 0), + ); + t( + "CONTROL: and in the package but outside its own src/ (one directory up), it still FAILS", + verdictIs(completenessOf('packages/cli/utils/skills-install-state.ts'), 1, 0), + ); + t( + 'the same site in a test file FAILS — beside the shipped file, by name', + verdictIs(completenessOf('packages/cli/src/utils/skills-install-state.test.ts'), 1, 0), + ); + t( + 'and in a test helper under src/__tests__/, by directory — the stricter test predicate holds it', + verdictIs(completenessOf('packages/cli/src/__tests__/staging-helper.ts'), 1, 0), + ); + t( + 'CONTROL: the test file with a base the scan CAN read (the system temp directory) is in neither list', + verdictIs(completenessOf('packages/cli/src/utils/skills-install-state.test.ts', tmpdirSource), 0, 0), + ); + t( + 'the same site in repo tooling FAILS — the tooling population is not dropped with the test predicate', + verdictIs(completenessOf('scripts/pm/stage-skills.mjs'), 1, 0) && !isTestFilePath('scripts/pm/stage-skills.mjs'), + ); + t( + 'CONTROL: the tooling file with a base the scan CAN read is in neither list', + verdictIs(completenessOf('scripts/pm/stage-skills.mjs', tmpdirSource), 0, 0), + ); + t( + 'and an unresolved mkdirSync site is in neither list — that half was never held to completeness', + verdictIs(completenessOf('scripts/pm/stage-skills.mjs', 'mkdirSync(join(dir, SKILLS_STAGING_PREFIX));'), 0, 0) + && scratchDirSitesInSource('scripts/pm/stage-skills.mjs', 'mkdirSync(join(dir, SKILLS_STAGING_PREFIX));').unresolved.length === 1, + ); + // The default package list is THIS tree's workspace, read from its manifest + // globs: the arms above hold on it too, not only on a hand-built list. + const liveDefault = (rel) => mkdtempCompleteness(scratchDirSitesInSource(rel, callerDirSource).unresolved); + t( + "on this tree's own workspace, the shipped arm is REPORTED and the tooling arm FAILS", + verdictIs(liveDefault('packages/cli/src/utils/skills-install-state.ts'), 0, 1) + && verdictIs(liveDefault('scripts/pm/stage-skills.mjs'), 1, 0) + && isShippedPackageSource('packages/cli/src/utils/skills-install-state.ts', completenessPackages), + ); + slow("the change set derived from git — temporary repositories with real history", () => { // ── The change set derived from git (#9320) ─────────────────────────────── // @@ -11851,14 +11916,21 @@ export function selfTest({ tier = 'full' } = {}) { }`, liveScratch.exposed.length === 0, ); - const unreadableTempSites = liveScratch.unresolved.filter((s) => s.call === 'mkdtempSync'); - t( - `no mkdtempSync site in this tree takes a base the scan cannot read${ - unreadableTempSites.length - ? ` — UNRESOLVED: ${unreadableTempSites.map((s) => `${s.file}:${s.line} (${s.why})`).join(', ')}` + // Completeness holds in test files and repo tooling; an unresolved site in + // shipped package source is REPORTED on this line and not failed, because + // its base is the user's run-time choice (`mkdtempCompleteness`, pinned in + // the fast tier; ruling record 7075362923). + const completeness = mkdtempCompleteness(liveScratch.unresolved); + const siteList = (sites) => sites.map((s) => `${s.file}:${s.line} (${s.why})`).join(', '); + t( + `no mkdtempSync site in a test file or repo tooling takes a base the scan cannot read${ + completeness.failing.length ? ` — UNRESOLVED: ${siteList(completeness.failing)}` : '' + }${ + completeness.reported.length + ? ` — reported, not failed (shipped package source, base chosen at run time): ${siteList(completeness.reported)}` : '' }`, - unreadableTempSites.length === 0, + completeness.failing.length === 0, ); } finally { rmSync(gitTmp, { recursive: true, force: true }); From 72d553754f5d1ea2e8c2a010f827a69942b1d09e Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 06:49:35 +0000 Subject: [PATCH 2/3] docs(pm): date the sweep header's measurement to this change's head Claude-Session: https://claude.ai/code/session_01QsR2jTeURPvEm465RcoYEC Co-authored-by: Claude --- scripts/pm/dispatch-gates.mjs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/pm/dispatch-gates.mjs b/scripts/pm/dispatch-gates.mjs index 598d447ffea..4c33ec56019 100644 --- a/scripts/pm/dispatch-gates.mjs +++ b/scripts/pm/dispatch-gates.mjs @@ -8724,11 +8724,12 @@ export function trackedPrefixes(files) { // chosen at run time by whoever runs the published code (ruling record // 7075362923). // -// Measured on 2026-11-22 at 3f7fdd00 through `scratchDirSitesInSource` and -// `isShippedPackageSource`: 1821 `mkdtempSync` sites — 1463 in `isTestFilePath` -// test files (47 in the tree), 344 in repo tooling and the other non-package -// sources (0 in the tree), 14 in shipped package source (all in the system -// temp directory); 0 unresolved in any population. +// Measured on 2026-11-22 at 80421551 (the same at its base 3f7fdd00) through +// `scratchDirSitesInSource` and `isShippedPackageSource`: 1821 `mkdtempSync` +// sites — 1463 in `isTestFilePath` test files (47 in the tree), 344 in repo +// tooling and the other non-package sources (0 in the tree), 14 in shipped +// package source (all in the system temp directory); 0 unresolved in any +// population. // // `mkdirSync` is swept too and deliberately NOT held to completeness: of its // sites, ~124 take a base this resolver cannot see (a function parameter, a From 3ec2a452021883bd855adc1ffd83aee5c000e265 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 08:40:16 +0000 Subject: [PATCH 3/3] fix(pm): a private workspace member's src/ stays held by mkdtempSync completeness Shipped package source now means the own src/ of a workspace member whose manifest is not private: true, read from the enumerator's workspacePackages pairs: a private member (example app, QA harness, docs app) is not published code, so an unresolved site in its src/ keeps failing. New fast pins: the private-member arm against the published arm, and a control under the member but in a src/ that is not its own (packages/cli/scripts/src/), which reds if the member prefix is loosened. The header names the non-shipped bucket honestly and dates its measurement by the base tree. Claude-Session: https://claude.ai/code/session_01QsR2jTeURPvEm465RcoYEC Co-authored-by: Claude --- scripts/pm/dispatch-gates.mjs | 50 ++++++++++++++----------- scripts/pm/dispatch-gates.self-test.mjs | 42 +++++++++++++++++---- 2 files changed, 64 insertions(+), 28 deletions(-) diff --git a/scripts/pm/dispatch-gates.mjs b/scripts/pm/dispatch-gates.mjs index 4c33ec56019..393f1d0769a 100644 --- a/scripts/pm/dispatch-gates.mjs +++ b/scripts/pm/dispatch-gates.mjs @@ -468,7 +468,7 @@ import { SCANNED_ROOTS as RUNNER_ENV_SCANNED_ROOTS, findRunnerEnvReads, isProduc import { findViolations as findErrorCodeCasingViolations } from '../check-error-code-casing.mjs'; // The workspace parse the README claim net (#31292) reads its population through, the one the gate itself imports. // Dependency-free, and it declares no path population of its own. -import { WORKSPACE_FILE, parseWorkspaceGlobs, workspacePackageDirs } from '../workspace-enumerator.mjs'; +import { WORKSPACE_FILE, parseWorkspaceGlobs, workspacePackageDirs, workspacePackages } from '../workspace-enumerator.mjs'; // The hand-written tables — ledgers, marker grammars, the change-kind roster, the tier globs — are // DATA, and live beside this file; this engine loads them, matches paths against them and derives. // Every table is re-exported under the name it always had, so no consumer moved. @@ -8719,17 +8719,18 @@ export function trackedPrefixes(files) { // over the sites nobody measured. // // The boundary of that rule is the FILE POPULATION: an unresolved site in -// shipped package source (a non-test file under a workspace package's `src/`, -// `isShippedPackageSource`) is REPORTED and not failed, because its base is -// chosen at run time by whoever runs the published code (ruling record -// 7075362923). +// shipped package source (a non-test file under the own `src/` of a workspace +// member whose manifest is not `private: true`, `isShippedPackageSource`) is +// REPORTED and not failed, because its base is chosen at run time by whoever +// runs the published code (ruling record 7075362923). // -// Measured on 2026-11-22 at 80421551 (the same at its base 3f7fdd00) through -// `scratchDirSitesInSource` and `isShippedPackageSource`: 1821 `mkdtempSync` -// sites — 1463 in `isTestFilePath` test files (47 in the tree), 344 in repo -// tooling and the other non-package sources (0 in the tree), 14 in shipped -// package source (all in the system temp directory); 0 unresolved in any -// population. +// Measured on 2026-11-22 on the tree of d8599c2c through +// `scratchDirSitesInSource` and `isShippedPackageSource`: 1823 `mkdtempSync` +// sites — 1465 in `isTestFilePath` test files (47 in the tree), 344 in every +// other source outside shipped package source (repo tooling, package scripts, +// test helpers and tests by directory; 0 in the tree; 0 of them under a private +// member's `src/`), 14 in shipped package source (all in the system temp +// directory); 0 unresolved in any population. // // `mkdirSync` is swept too and deliberately NOT held to completeness: of its // sites, ~124 take a base this resolver cannot see (a function parameter, a @@ -10018,15 +10019,22 @@ export function exposedScratchDirs({ cwd = ROOT, files = null } = {}) { * exactly what an unresolved site does not know. ⛔ Nor is it "not a test * file" alone — repo tooling is code this checkout runs, and it stays held. * - * Shipped package source = a non-test source under a workspace package's own - * `src/`. "Non-test" is the runner-env gate's `isProductSource` (a test by name - * or by directory, `.d.ts` excluded), the stricter of the tree's test - * predicates, so a helper under `src/__tests__/` stays held; "workspace - * package" is a workspace member holding a manifest, from the enumerator. - * Neither half is a list kept here. + * Shipped package source = a non-test source under the own `src/` of a + * published workspace member. "Non-test" is the runner-env gate's + * `isProductSource` (a test by name or by directory, `.d.ts` excluded), the + * stricter of the tree's test predicates, so a helper under `src/__tests__/` + * stays held. "Published member" is a workspace member whose manifest is not + * `private: true`, as the enumerator's `workspacePackages` pairs them: a + * private member (an example app, a QA harness, the docs app) is not published + * code and has no such user, so its `src/` is code this checkout runs and stays + * held, as does a member whose manifest does not parse. Neither half is a list + * kept here. + * + * `members` is `workspacePackages(root)`'s shape: `{ dir, manifest }` pairs. */ -export function isShippedPackageSource(rel, packageDirs) { - return isRunnerEnvProductSource(rel) && packageDirs.some((dir) => rel.startsWith(`${dir}/src/`)); +export function isShippedPackageSource(rel, members) { + return isRunnerEnvProductSource(rel) + && members.some(({ dir, manifest }) => manifest?.private !== true && rel.startsWith(`${dir}/src/`)); } /** @@ -10035,12 +10043,12 @@ export function isShippedPackageSource(rel, packageDirs) { * and does not fail. A `mkdirSync` site is in neither — that half was never * held to completeness (the header above). */ -export function mkdtempCompleteness(unresolved, { packageDirs = workspacePackageDirs(ROOT) } = {}) { +export function mkdtempCompleteness(unresolved, { members = workspacePackages(ROOT) } = {}) { const failing = []; const reported = []; for (const site of unresolved) { if (site.call !== 'mkdtempSync') continue; - (isShippedPackageSource(site.file, packageDirs) ? reported : failing).push(site); + (isShippedPackageSource(site.file, members) ? reported : failing).push(site); } return { failing, reported }; } diff --git a/scripts/pm/dispatch-gates.self-test.mjs b/scripts/pm/dispatch-gates.self-test.mjs index a8de9c527c4..344d90bc9e4 100644 --- a/scripts/pm/dispatch-gates.self-test.mjs +++ b/scripts/pm/dispatch-gates.self-test.mjs @@ -11464,9 +11464,9 @@ export function selfTest({ tier = 'full' } = {}) { // beside a caller's directory. Each arm has a control one step away. const callerDirSource = 'const staging = mkdtempSync(join(dir, SKILLS_STAGING_PREFIX));'; const tmpdirSource = 'const staging = mkdtempSync(join(tmpdir(), SKILLS_STAGING_PREFIX));'; - const completenessPackages = ['packages/cli']; - const completenessOf = (rel, source = callerDirSource, packageDirs = completenessPackages) => - mkdtempCompleteness(scratchDirSitesInSource(rel, source).unresolved, { packageDirs }); + const completenessPackages = [{ dir: 'packages/cli', manifest: { name: '@objectstack/cli' } }]; + const completenessOf = (rel, source = callerDirSource, members = completenessPackages) => + mkdtempCompleteness(scratchDirSitesInSource(rel, source).unresolved, { members }); const verdictIs = (v, failing, reported) => v.failing.length === failing && v.reported.length === reported; const shippedVerdict = completenessOf('packages/cli/src/utils/skills-install-state.ts'); t( @@ -11476,12 +11476,37 @@ export function selfTest({ tier = 'full' } = {}) { ); t( 'CONTROL: the same file in a directory that holds no workspace package still FAILS', - verdictIs(completenessOf('packages/cli/src/utils/skills-install-state.ts', callerDirSource, ['packages/core']), 1, 0), + verdictIs( + completenessOf('packages/cli/src/utils/skills-install-state.ts', callerDirSource, [{ dir: 'packages/core', manifest: {} }]), + 1, + 0, + ), ); t( "CONTROL: and in the package but outside its own src/ (one directory up), it still FAILS", verdictIs(completenessOf('packages/cli/utils/skills-install-state.ts'), 1, 0), ); + // A src/ segment of the member's that is NOT its own src/: product source by + // name (so `isProductSource` alone would pass it), under the member, and red + // the day the member prefix is loosened from MEMBER/src/ to MEMBER/. + t( + "CONTROL: under the member but in a src/ that is not the member's own (packages/cli/scripts/src/), it still FAILS", + verdictIs(completenessOf('packages/cli/scripts/src/staging.ts'), 1, 0) + && runnerEnvIsProductSource('packages/cli/scripts/src/staging.ts'), + ); + // A private member is not published code: its src/ is code this checkout + // runs (an example app, a QA harness), so the same site there FAILS. The + // control is the published arm above, the same path with the flag absent. + t( + "a private: true member's src/ is not shipped source — the same site there FAILS", + verdictIs( + completenessOf('packages/cli/src/utils/skills-install-state.ts', callerDirSource, [ + { dir: 'packages/cli', manifest: { name: '@objectstack/cli', private: true } }, + ]), + 1, + 0, + ), + ); t( 'the same site in a test file FAILS — beside the shipped file, by name', verdictIs(completenessOf('packages/cli/src/utils/skills-install-state.test.ts'), 1, 0), @@ -11507,13 +11532,16 @@ export function selfTest({ tier = 'full' } = {}) { verdictIs(completenessOf('scripts/pm/stage-skills.mjs', 'mkdirSync(join(dir, SKILLS_STAGING_PREFIX));'), 0, 0) && scratchDirSitesInSource('scripts/pm/stage-skills.mjs', 'mkdirSync(join(dir, SKILLS_STAGING_PREFIX));').unresolved.length === 1, ); - // The default package list is THIS tree's workspace, read from its manifest - // globs: the arms above hold on it too, not only on a hand-built list. + // The default member list is THIS tree's workspace, read from its manifest + // globs and manifests: the arms above hold on it too, not only on a + // hand-built list — packages/qa/dogfood is a private member of this tree. const liveDefault = (rel) => mkdtempCompleteness(scratchDirSitesInSource(rel, callerDirSource).unresolved); t( - "on this tree's own workspace, the shipped arm is REPORTED and the tooling arm FAILS", + "on this tree's own workspace, the shipped arm is REPORTED, the tooling and private-member arms FAIL", verdictIs(liveDefault('packages/cli/src/utils/skills-install-state.ts'), 0, 1) && verdictIs(liveDefault('scripts/pm/stage-skills.mjs'), 1, 0) + && verdictIs(liveDefault('packages/qa/dogfood/src/staging.ts'), 1, 0) + && JSON.parse(readFileSync(nodePath.join(ROOT, 'packages/qa/dogfood/package.json'), 'utf8')).private === true && isShippedPackageSource('packages/cli/src/utils/skills-install-state.ts', completenessPackages), );