Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 68 additions & 7 deletions scripts/pm/dispatch-gates.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -8713,13 +8713,24 @@ 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 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 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
Expand Down Expand Up @@ -9992,6 +10003,56 @@ 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 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, members) {
return isRunnerEnvProductSource(rel)
&& members.some(({ dir, manifest }) => manifest?.private !== true && 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, { members = workspacePackages(ROOT) } = {}) {
const failing = [];
const reported = [];
for (const site of unresolved) {
if (site.call !== 'mkdtempSync') continue;
(isShippedPackageSource(site.file, members) ? 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;
Expand Down
112 changes: 106 additions & 6 deletions scripts/pm/dispatch-gates.self-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ import {
isInRootTsProgram,
isNonPathNamespace,
isPlainTopLevelDir,
isShippedPackageSource,
isTestFilePath,
isTypeCheckInvocation,
jobFilterOutputRefs,
Expand All @@ -210,6 +211,7 @@ import {
maskShellComments,
metadataFormModulePaths,
metadataFormsSurfaceIsExtracted,
mkdtempCompleteness,
liveDerivationInputs,
narrowToDerivationInputs,
notRunnableCommandSet,
Expand Down Expand Up @@ -11452,6 +11454,97 @@ 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 = [{ 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(
"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, [{ 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),
);
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 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, 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),
);

slow("the change set derived from git — temporary repositories with real history", () => {
// ── The change set derived from git (#9320) ───────────────────────────────
//
Expand Down Expand Up @@ -11851,14 +11944,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 });
Expand Down
Loading