Merge remote-tracking branch 'origin/main' into fix/r9-precache-bound-diagnostics
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { readdir } from "node:fs/promises";
|
||||
import { readdir, readFile } from "node:fs/promises";
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
import { declaredCspProblems } from "./lib/csp-policy.ts";
|
||||
|
||||
function requiredPnpmCli(): string {
|
||||
const executable = process.env.npm_execpath;
|
||||
if (!executable) {
|
||||
@@ -35,15 +37,28 @@ const forbidden = runPnpm([
|
||||
const distFiles = await readdir("dist", { recursive: true });
|
||||
const publicSourceMaps = distFiles.filter((file) => String(file).endsWith(".map"));
|
||||
|
||||
if (allowed.status !== 0 || forbidden.status === 0 || publicSourceMaps.length > 0) {
|
||||
const SECURITY_HEADERS = "config/hosting/security-headers.json";
|
||||
const cspProblems = declaredCspProblems(await readFile(SECURITY_HEADERS, "utf8"));
|
||||
|
||||
if (
|
||||
allowed.status !== 0 ||
|
||||
forbidden.status === 0 ||
|
||||
publicSourceMaps.length > 0 ||
|
||||
cspProblems.length > 0
|
||||
) {
|
||||
process.stderr.write(allowed.stderr || allowed.stdout);
|
||||
process.stderr.write(forbidden.stderr || forbidden.stdout);
|
||||
if (publicSourceMaps.length > 0) {
|
||||
process.stderr.write(`Public source maps found: ${publicSourceMaps.join(", ")}\n`);
|
||||
}
|
||||
if (cspProblems.length > 0) {
|
||||
process.stderr.write(
|
||||
`${SECURITY_HEADERS} Content-Security-Policy: ${cspProblems.join("; ")}\n`,
|
||||
);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
process.stdout.write(
|
||||
"Browser security fixtures: injection rejected, public source maps absent\n",
|
||||
"Browser security fixtures: injection rejected, public source maps absent, declared CSP allows no unsafe source\n",
|
||||
);
|
||||
|
||||
@@ -5,6 +5,7 @@ import { loadCiGateContract } from "./contracts/ci-gates.ts";
|
||||
import { loadProductCiOverlay } from "./contracts/product-ci-overlay.ts";
|
||||
import {
|
||||
gatedTestPaths,
|
||||
gatedTestTargets,
|
||||
listTestFiles,
|
||||
parseUngatedTestExclusions,
|
||||
ungatedTestFailures,
|
||||
@@ -38,7 +39,7 @@ try {
|
||||
failures.push(
|
||||
...ungatedTestFailures({
|
||||
testFiles: await listTestFiles(process.cwd()),
|
||||
gatedPaths: gatedTestPaths(
|
||||
gatedPaths: gatedTestTargets(
|
||||
packageScripts,
|
||||
[...contract.commands.map(({ script }) => script), ...productGateScripts],
|
||||
(file) => readFileSync(file, "utf8"),
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import {
|
||||
checkDeclaredCspFixtures,
|
||||
checkNonmatchingSecurityIncludeFixture,
|
||||
checkSecurityFixtures,
|
||||
} from "./lib/security-fixture-check.ts";
|
||||
|
||||
await checkNonmatchingSecurityIncludeFixture();
|
||||
await checkSecurityFixtures();
|
||||
await checkDeclaredCspFixtures();
|
||||
process.stdout.write(
|
||||
"Security fixtures: unmatched include rejected; 3 forbidden files detected\n",
|
||||
"Security fixtures: unmatched include rejected; 3 forbidden files detected; unsafe CSP fixture rejected\n",
|
||||
);
|
||||
|
||||
@@ -88,14 +88,24 @@ export async function findSystemTestPrerequisiteFailures(
|
||||
}
|
||||
|
||||
if (executable.get(BWRAP)) {
|
||||
const probe = host.spawn(BWRAP, NAMESPACE_PROBE_ARGUMENTS, PROBE_TIMEOUT_MS);
|
||||
if (probe.error || probe.status !== 0) {
|
||||
failures.push(await namespaceFailure(host, probe));
|
||||
}
|
||||
const failure = await findProviderSandboxNamespaceFailure(host);
|
||||
if (failure !== undefined) failures.push(failure);
|
||||
}
|
||||
return failures;
|
||||
}
|
||||
|
||||
/**
|
||||
* 1101/13-03. Whether this host lets the provider sandbox create its
|
||||
* namespaces, and if not, why and what to do. The release provider jobs run
|
||||
* it before the provider (scripts/run-and-validate-provider.ts).
|
||||
*/
|
||||
export async function findProviderSandboxNamespaceFailure(
|
||||
host: SystemTestHost = nodeSystemTestHost,
|
||||
): Promise<string | undefined> {
|
||||
const probe = host.spawn(BWRAP, NAMESPACE_PROBE_ARGUMENTS, PROBE_TIMEOUT_MS);
|
||||
return probe.error || probe.status !== 0 ? namespaceFailure(host, probe) : undefined;
|
||||
}
|
||||
|
||||
async function namespaceFailure(
|
||||
host: SystemTestHost,
|
||||
probe: ReturnType<SystemTestHost["spawn"]>,
|
||||
|
||||
@@ -432,6 +432,9 @@ const jobSchema = z
|
||||
browserGateIds: z.array(id).max(64),
|
||||
environment: z.array(environmentBindingSchema).max(32),
|
||||
steps: z.array(jobStepSchema).min(1).max(64),
|
||||
// 1101/13-03. What the runner of a job without a gate needs (the provider
|
||||
// jobs' sandbox). Rendered beside its runner label like a gate's.
|
||||
hostRequirements: z.array(nonEmpty.max(512)).min(1).max(8).optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
@@ -862,6 +865,20 @@ function validateContractSemantics(
|
||||
// paired backend's nightly lanes.
|
||||
main_gate: ["FE-GATE-029", "FE-GATE-030"],
|
||||
};
|
||||
// 1101/13-03. The provider jobs run FE-GATE-013's sandbox (systemd-run
|
||||
// scope, bwrap with the same namespace options), so they need its host.
|
||||
const sandboxRequirements = JSON.stringify(
|
||||
contract.gates.find(({ id: gateId }) => gateId === "FE-GATE-013")?.hostRequirements ?? [],
|
||||
);
|
||||
for (const job of contract.jobs) {
|
||||
if (job.kind === "provider") {
|
||||
if (JSON.stringify(job.hostRequirements ?? []) !== sandboxRequirements) {
|
||||
issue(`provider job host requirements must equal FE-GATE-013's: ${job.id}`);
|
||||
}
|
||||
} else if (job.hostRequirements !== undefined) {
|
||||
issue(`only a provider job declares host requirements of its own: ${job.id}`);
|
||||
}
|
||||
}
|
||||
if (JSON.stringify(contract.jobs.map(({ id }) => id)) !== JSON.stringify(Object.keys(expectedJobOwnership))) {
|
||||
issue("job registry must contain the exact thirteen canonical jobs in semantic order");
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ function baseOf(id: string): string {
|
||||
: id;
|
||||
}
|
||||
|
||||
function namesOf(id: string) {
|
||||
export function namesOf(id: string) {
|
||||
const base = baseOf(id);
|
||||
const pascal = base
|
||||
.split("-")
|
||||
|
||||
@@ -267,11 +267,17 @@ function renderHostRequirements(
|
||||
job: CiWorkflowJob,
|
||||
index: ReturnType<typeof indexCiGateContract>,
|
||||
): string[] {
|
||||
return job.gateIds.flatMap((gateId) =>
|
||||
(index.gates.get(gateId)?.hostRequirements ?? []).map(
|
||||
(requirement) => ` # ${gateId} runner requirement: ${requirement}`,
|
||||
return [
|
||||
...job.gateIds.flatMap((gateId) =>
|
||||
(index.gates.get(gateId)?.hostRequirements ?? []).map(
|
||||
(requirement) => ` # ${gateId} runner requirement: ${requirement}`,
|
||||
),
|
||||
),
|
||||
);
|
||||
// 1101/13-03. A provider job runs the provider sandbox and has no gate.
|
||||
...(job.hostRequirements ?? []).map(
|
||||
(requirement) => ` # provider sandbox runner requirement: ${requirement}`,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,8 +25,8 @@ Bash 직후 ──> post-bash ──> desktop에서 pnpm·게이트를 돌
|
||||
| N2 | 같은 때, `*.md` | `scripts/check-work-docs.py`를 돌린다(작업 매뉴얼의 분량·이력 ID·뼈대·상대 링크) | 실패 줄. 고친 문서를 가리키는 줄이 있으면 그것만 |
|
||||
| N5 | Stop | 이 세션에서 desktop만 확인할 수 있는 파일(아래 밖의 모든 파일)을 고친 뒤 desktop 실행이 없으면 턴을 한 번 막고 이유를 준다 | `decision: block`, 다음 편집 전까지 한 번 |
|
||||
|
||||
- N5가 "desktop 실행"으로 치는 것: `ssh <desktop 호스트> …`로 pnpm·`ci:gate`·`verify.sh`·vitest·playwright·`node scripts/…`를 돌린 명령, 또는 `scripts/verify.sh`를 `docs`·`hooks` 밖 단계로(`--on here` 없이) 돌린 명령.
|
||||
- N5가 세지 않는 파일(노트북에서 확인되는 것): `.claude/`, `scripts/hooks/`, `scripts/tests/`, `scripts/check-work-docs.py`, `docs/ledger/`, `CLAUDE.md`, `src/**/AGENTS.md`·`CLAUDE.md`. 이것들은 `scripts/verify.sh docs`·`hooks`가 노트북에서 본다.
|
||||
- N5가 "desktop 실행"으로 치는 것: `ssh <desktop 호스트> …`로 pnpm·`ci:gate`·`verify.sh`·vitest·playwright·`node scripts/…`를 돌린 명령(로그를 읽기만 하는 `cat`·`grep`·`tail` 등은 빼고), 또는 `scripts/verify.sh`를 명령으로 `docs`·`hooks` 밖 단계로(`--on here`·`--dry-run` 없이) 돌린 명령. 앞의 `VAR=값`과 `timeout`·`nohup`·`bash` 같은 감싸는 낱말, ssh 옵션과 그 값(`-o BatchMode=yes`, `-p 22`)은 건너뛴다. `verify.sh`를 읽는 명령(`sed`, `grep`, `git log -- scripts/verify.sh`)은 세지 않는다.
|
||||
- N5가 세지 않는 파일(노트북에서 확인되는 것): `.claude/`의 설정·훅 상태, `scripts/hooks/`·`scripts/tests/`의 코드, `scripts/check-work-docs.py`, `docs/ledger/`의 장부. 이것들은 `scripts/verify.sh docs`·`hooks`가 노트북에서 본다. 그 폴더의 문서(`.md`)와 `CLAUDE.md`, `src/**/AGENTS.md`·`CLAUDE.md`는 desktop `verify:documentation`도 보므로 센다.
|
||||
- N5가 기억하는 것은 `.claude/hook-state/<session_id>.json`이다(git이 무시한다).
|
||||
- 권한 쪽 차단: `.claude/settings.json`의 `permissions.deny`가 실제 `.env`·`.env.local`·`.env.*.local`·`.env.<mode>` 읽기·쓰기를 막는다. `.env.example`은 막지 않는다.
|
||||
|
||||
|
||||
+70
-18
@@ -70,21 +70,32 @@ DOC_CHECK = ("scripts/check-work-docs.py",)
|
||||
DOC_TIMEOUT = 20
|
||||
|
||||
# --- N5: an edit that only the desktop can check, until a desktop run --------------------------------------
|
||||
# Laptop-checkable on their own: the hooks and their tests, the work-manual checker, the ledger, Claude
|
||||
# settings, CLAUDE.md and the folder rule books under src/ (scripts/check-work-docs.py checks them). Everything else is checked by gates that need pnpm.
|
||||
# Laptop-checkable on their own: the hooks and their tests, the work-manual checker, the ledger and the
|
||||
# Claude settings, documents left out. Everything else is checked by gates that need pnpm, documents
|
||||
# included: verify:documentation reads CLAUDE.md, the folder rule books under src/, .claude/**/*.md and
|
||||
# the module READMEs of scripts/hooks/ and docs/ledger/ too (1112/08-04).
|
||||
LAPTOP_ONLY = (
|
||||
re.compile(r"^\.claude/"),
|
||||
re.compile(r"^scripts/hooks/"),
|
||||
re.compile(r"^scripts/tests/"),
|
||||
re.compile(r"^\.claude/(?!.*\.md$)"),
|
||||
re.compile(r"^scripts/hooks/(?!.*\.md$)"),
|
||||
re.compile(r"^scripts/tests/(?!.*\.md$)"),
|
||||
re.compile(r"^scripts/check-work-docs\.py$"),
|
||||
re.compile(r"^docs/ledger/"),
|
||||
re.compile(r"^CLAUDE\.md$"),
|
||||
re.compile(r"^src/(?:.+/)?(?:AGENTS|CLAUDE)\.md$"),
|
||||
re.compile(r"^docs/ledger/(?!.*\.md$)"),
|
||||
)
|
||||
DESKTOP_HOST = re.compile(r"desktop")
|
||||
DESKTOP_WORK = re.compile(r"\b(?:pnpm|ci:gate|verify\.sh|vitest|playwright)\b|\bnode\s+scripts/")
|
||||
VERIFY = re.compile(r"(?:^|[\s;&|(])(?:\./)?scripts/verify\.sh\s+(\S+)(.*)")
|
||||
LAPTOP_STAGES = {"docs", "hooks"}
|
||||
# 1112/08-09. One command of a shell line: what follows ;, &&, ||, |, ( or a newline.
|
||||
COMMAND_SEPARATOR = re.compile(r"&&|\|\||;|\||\(|\)|\n")
|
||||
# Words that run the next command: `timeout 900 scripts/verify.sh …`, `bash scripts/verify.sh …`.
|
||||
WRAPPERS = {"timeout": 1, "nohup": 0, "setsid": 0, "env": 0, "time": 0, "exec": 0, "bash": 0, "sh": 0}
|
||||
# ssh options that take the next word as their value (`ssh -o BatchMode=yes desktop …`).
|
||||
SSH_VALUE_OPTIONS = {"-B", "-b", "-c", "-D", "-E", "-e", "-F", "-I", "-i", "-J", "-L", "-l", "-m", "-O",
|
||||
"-o", "-P", "-p", "-Q", "-R", "-S", "-W", "-w"}
|
||||
# A remote command made only of these reads logs; it runs nothing.
|
||||
READ_ONLY = {"cat", "grep", "tail", "head", "less", "ls", "sed", "awk", "wc", "find", "stat", "echo",
|
||||
"printf", "date", "uptime", "ps", "test", "true", "for", "do", "done", "if", "then", "fi"}
|
||||
ASSIGNMENT = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*=")
|
||||
STEP_WORD = re.compile(r"^[a-z][a-z0-9-]*$")
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
@@ -277,20 +288,61 @@ def needs_desktop(path: str) -> bool:
|
||||
return not any(pattern.search(path) for pattern in LAPTOP_ONLY)
|
||||
|
||||
|
||||
def ran_on_desktop(command: str) -> bool:
|
||||
"""An `ssh <desktop> …` running pnpm or a gate, or scripts/verify.sh with a stage that goes there."""
|
||||
def split_words(text: str) -> list[str]:
|
||||
try:
|
||||
words = shlex.split(command)
|
||||
return shlex.split(text)
|
||||
except ValueError:
|
||||
words = command.split()
|
||||
return text.split()
|
||||
|
||||
|
||||
def command_words(segment: str) -> list[str]:
|
||||
"""The words of one command, its leading `VAR=value` and wrapper words dropped."""
|
||||
words = split_words(segment)
|
||||
while words:
|
||||
if ASSIGNMENT.match(words[0]):
|
||||
words = words[1:]
|
||||
elif words[0] in WRAPPERS:
|
||||
words = words[1 + WRAPPERS[words[0]]:]
|
||||
else:
|
||||
break
|
||||
return words
|
||||
|
||||
|
||||
def ssh_host_and_remote(words: list[str]) -> tuple[str | None, str]:
|
||||
"""The host and the remote command of the words after `ssh`, its options and their values skipped."""
|
||||
position = 0
|
||||
while position < len(words) and words[position].startswith("-"):
|
||||
position += 2 if words[position] in SSH_VALUE_OPTIONS else 1
|
||||
if position >= len(words):
|
||||
return None, ""
|
||||
return words[position], " ".join(words[position + 1:])
|
||||
|
||||
|
||||
def runs_only_reads(remote: str) -> bool:
|
||||
segments = [command_words(part) for part in COMMAND_SEPARATOR.split(remote)]
|
||||
return all(not words or words[0] in READ_ONLY for words in segments)
|
||||
|
||||
|
||||
def ran_on_desktop(command: str) -> bool:
|
||||
"""An `ssh <desktop> …` running pnpm or a gate, or scripts/verify.sh running a step that goes there.
|
||||
|
||||
1112/08-09. Reading verify.sh (`sed`, `grep`, `git log -- scripts/verify.sh`), `--dry-run` and
|
||||
an ssh that only reads logs run nothing on the desktop.
|
||||
"""
|
||||
words = split_words(command)
|
||||
for position, word in enumerate(words):
|
||||
if word.endswith("ssh"):
|
||||
hosts = [w for w in words[position + 1:position + 5] if not w.startswith("-")][:2]
|
||||
if any(DESKTOP_HOST.search(host) for host in hosts) and DESKTOP_WORK.search(command):
|
||||
host, remote = ssh_host_and_remote(words[position + 1:])
|
||||
if (host is not None and DESKTOP_HOST.search(host) and DESKTOP_WORK.search(remote)
|
||||
and not runs_only_reads(remote)):
|
||||
return True
|
||||
for match in VERIFY.finditer(command):
|
||||
stage, rest = match.group(1), match.group(2)
|
||||
if stage not in LAPTOP_STAGES and not re.search(r"--on\s+here\b", rest):
|
||||
for segment in COMMAND_SEPARATOR.split(command):
|
||||
words = command_words(segment)
|
||||
if len(words) < 2 or not re.search(r"(?:^|/)scripts/verify\.sh$", words[0]):
|
||||
continue
|
||||
step, flags = words[1], words[2:]
|
||||
if (STEP_WORD.match(step) and step not in LAPTOP_STAGES and "--dry-run" not in flags
|
||||
and not re.search(r"--on\s+here\b", " ".join(flags))):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 1112/08-13. What a failed `ci:gate` prints to stderr: the gate, the command
|
||||
* that failed (or that none did), the log with the whole output, and the end
|
||||
* of that output, where the cause usually is.
|
||||
*/
|
||||
export function formatGateFailure(input: Readonly<{
|
||||
gateId: string;
|
||||
gateName: string;
|
||||
logPath: string;
|
||||
failedCommand?: string | undefined;
|
||||
output: readonly string[];
|
||||
tailLines?: number;
|
||||
}>): string {
|
||||
const tail = input.output
|
||||
.flatMap((chunk) => chunk.split(/\r?\n/u))
|
||||
.filter((line) => line.trim() !== "")
|
||||
.slice(-(input.tailLines ?? 20));
|
||||
return [
|
||||
`${input.gateId} ${input.gateName}: FAIL`,
|
||||
` failed command: ${input.failedCommand ?? "none (a check outside the commands)"}`,
|
||||
` log: ${input.logPath}`,
|
||||
" last lines of the log:",
|
||||
...tail.map((line) => ` ${line}`),
|
||||
].join("\n");
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* 0929/13-04. What the declared Content-Security-Policy
|
||||
* (config/hosting/security-headers.json) may not allow.
|
||||
* scripts/verify-hosting-headers.ts compares a host's answer with it; this
|
||||
* reads what it allows. check:browser-security (FE-GATE-013) runs it, and
|
||||
* check:security:fixtures (FE-GATE-029) holds it to a rejected fixture.
|
||||
*/
|
||||
const UNSAFE_SOURCES = new Set(["'unsafe-inline'", "'unsafe-eval'", "*"]);
|
||||
/** Directives whose sources decide what script or plugin code may run or style may apply. */
|
||||
const CODE_DIRECTIVES = new Set([
|
||||
"default-src",
|
||||
"script-src",
|
||||
"script-src-elem",
|
||||
"script-src-attr",
|
||||
"style-src",
|
||||
"style-src-elem",
|
||||
"style-src-attr",
|
||||
"object-src",
|
||||
]);
|
||||
/** A scheme-only source (`https:`) lets any host on it run script. */
|
||||
const SCHEME_ONLY = /^[a-z][a-z0-9+.-]*:$/u;
|
||||
const SCRIPT_DIRECTIVES = new Set(["default-src", "script-src", "script-src-elem", "object-src"]);
|
||||
|
||||
/**
|
||||
* The directives as a browser reads them (CSP3): names and keywords in any
|
||||
* case, and the first of a repeated directive, the later ones ignored.
|
||||
*/
|
||||
function directivesOf(policy: string): Map<string, readonly string[]> {
|
||||
const directives = new Map<string, readonly string[]>();
|
||||
for (const part of policy.split(";")) {
|
||||
const [name, ...sources] = part.trim().split(/\s+/u);
|
||||
const key = name?.toLowerCase();
|
||||
if (key && !directives.has(key)) {
|
||||
directives.set(key, sources.map((source) => source.toLowerCase()));
|
||||
}
|
||||
}
|
||||
return directives;
|
||||
}
|
||||
|
||||
export function cspPolicyProblems(policy: string): string[] {
|
||||
const directives = directivesOf(policy);
|
||||
const problems: string[] = [];
|
||||
if (!directives.has("script-src") && !directives.has("default-src")) {
|
||||
problems.push("no script-src and no default-src");
|
||||
}
|
||||
for (const [name, sources] of directives) {
|
||||
if (!CODE_DIRECTIVES.has(name)) continue;
|
||||
for (const source of sources) {
|
||||
if (UNSAFE_SOURCES.has(source)) problems.push(`${name} allows ${source}`);
|
||||
else if (SCRIPT_DIRECTIVES.has(name) && SCHEME_ONLY.test(source)) {
|
||||
problems.push(`${name} allows the whole scheme ${source}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
|
||||
/**
|
||||
* The problems of the policy a security-headers document (the shape of
|
||||
* config/hosting/security-headers.json) declares, its header name in any case.
|
||||
*/
|
||||
export function declaredCspProblems(securityHeadersJson: string): string[] {
|
||||
const document = JSON.parse(securityHeadersJson) as { headers?: Record<string, unknown> };
|
||||
const policy = Object.entries(document.headers ?? {}).find(
|
||||
([name]) => name.toLowerCase() === "content-security-policy",
|
||||
)?.[1];
|
||||
return typeof policy === "string"
|
||||
? cspPolicyProblems(policy)
|
||||
: ["no Content-Security-Policy header"];
|
||||
}
|
||||
+129
-12
@@ -9,8 +9,16 @@ import path from "node:path";
|
||||
* - `src/`: any file whose path or text still names the feature ID or its
|
||||
* folder. Platform source never names a product feature, so a name left
|
||||
* there is a reference the type checker cannot see (a catalog key, a
|
||||
* runtime override, a link).
|
||||
* - `tests/`: a file named after the feature, or one that imports from the
|
||||
* runtime override, a link). The name counts as a whole name only: in the
|
||||
* text, case-sensitive with no identifier character (`[A-Za-z0-9_-]`) on
|
||||
* either side; in the path, a segment equal to it or whose part before the
|
||||
* first `.` is. A substring search counted ten template files for
|
||||
* `product-feature` (`product-features.ts`, `product-features-port.ts` and
|
||||
* their importers). `src/.generated/` is derived from the feature list and
|
||||
* left out. A one-word ID that is an ordinary word in the template
|
||||
* (`search`) can still be found in its text.
|
||||
* - `tests/`: a file named after the feature (the same path rule; the
|
||||
* template's `product-feature-switch.test.tsx` is not), or one that imports from the
|
||||
* feature's `src/features/<dir>/` or `tests/features/<dir>/`. A vitest
|
||||
* test's text is not searched for the bare name: the template's own tests
|
||||
* use example IDs as data (`tests/unit/create-feature.test.ts` writes
|
||||
@@ -25,14 +33,24 @@ import path from "node:path";
|
||||
* searched for the ID or folder name as written, case-sensitive, with no
|
||||
* identifier character (`[A-Za-z0-9_-]`) on either side. A longer name
|
||||
* that contains it (`generate-product-feature-index.ts` for
|
||||
* `product-feature`, `KO_MESSAGES` for `messages`) does not count. A spec
|
||||
* that names only the feature's routes or URLs is not found; 03's hand list
|
||||
* removes the feature's specs.
|
||||
* `product-feature`, `KO_MESSAGES` for `messages`) does not count.
|
||||
* Diff review DR-02: only a name with a hyphen is searched. A one-word ID
|
||||
* or folder (`status`, `reports`, `messages`) is an ordinary word in the
|
||||
* template's own specs (`status: 200`, `getByRole("status")`, "reports" in
|
||||
* a test title), and no text rule tells that from a reference, so a spec
|
||||
* that names only a one-word ID is not found either.
|
||||
* a test title), and no text rule tells that from a reference.
|
||||
* - 0925 FOLLOW-UP 09-07. A spec that opens the feature by its URL alone
|
||||
* (`page.goto("/invoices")`) failed only in FE-GATE-008, after the drill
|
||||
* passed. `routes.paths` are the removed feature's route paths: a spec, or
|
||||
* another file in a Playwright `testDir` that is not a vitest test (a page
|
||||
* object), with a string that opens one is residue. A string opens a route
|
||||
* when it starts with the route's fixed prefix (`/invoices` of
|
||||
* `/invoices/:id` or `/invoices/edit?`) followed by the string's end, `/`,
|
||||
* `?`, `#` or `${`, and no route left behind (`routes.remainingPaths`) has
|
||||
* a longer prefix that fits it. A prefix that is `/` is not searched.
|
||||
* `routes.ids`, the feature's route IDs, are searched in `src` text by the
|
||||
* whole-name rule. What is still not found: a spec that names only a
|
||||
* one-word ID, or builds the URL from parts. 03's hand list removes the
|
||||
* feature's specs.
|
||||
*
|
||||
* The drill applies the same rule to a sample a project lists in
|
||||
* scripts/lib/removable-template-features.ts.
|
||||
@@ -41,6 +59,18 @@ function escapeRegExp(value: string): string {
|
||||
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
||||
}
|
||||
|
||||
/**
|
||||
* The feature ID or folder as a whole name: case-sensitive, with no
|
||||
* identifier character (`[A-Za-z0-9_-]`) on either side. The drill searches
|
||||
* `src` text and the built `dist` with it; the template's own bundle holds
|
||||
* `data-product-feature` and `product-features`, which a substring search
|
||||
* counted for a feature named `product-feature`.
|
||||
*/
|
||||
export function featureNamePattern(featureId: string, directory: string): RegExp {
|
||||
const names = [...new Set([featureId, directory])].map(escapeRegExp).join("|");
|
||||
return new RegExp(`(?<![A-Za-z0-9_-])(?:${names})(?![A-Za-z0-9_-])`, "u");
|
||||
}
|
||||
|
||||
async function filesUnder(directory: string): Promise<string[]> {
|
||||
const entries = await readdir(directory, { withFileTypes: true }).catch(() => []);
|
||||
const nested = await Promise.all(
|
||||
@@ -52,13 +82,73 @@ async function filesUnder(directory: string): Promise<string[]> {
|
||||
return nested.flat();
|
||||
}
|
||||
|
||||
/**
|
||||
* The part of a route path before its first parameter, wildcard or optional
|
||||
* segment (`/invoices` of `/invoices/:id` or `/invoices/edit?`), or null when
|
||||
* that is `/`.
|
||||
*/
|
||||
function staticRoutePrefix(routePath: string): string | null {
|
||||
const segments: string[] = [];
|
||||
for (const segment of routePath.split("/").filter(Boolean)) {
|
||||
if (segment.startsWith(":") || segment.includes("*") || segment.endsWith("?")) break;
|
||||
segments.push(segment);
|
||||
}
|
||||
return segments.length === 0 ? null : `/${segments.join("/")}`;
|
||||
}
|
||||
|
||||
const prefixesOf = (routePaths: readonly string[]) =>
|
||||
new Set(routePaths.map(staticRoutePrefix).filter((prefix): prefix is string => prefix !== null));
|
||||
|
||||
/** `/invoices`, `/invoices/7`, `/invoices?tab=1`, `/invoices#x`, `/invoices${query}` open `/invoices`. */
|
||||
function opens(value: string, prefix: string): boolean {
|
||||
if (!value.startsWith(prefix)) return false;
|
||||
const rest = value.slice(prefix.length);
|
||||
return rest === "" || /^[/?#]/u.test(rest) || rest.startsWith("${");
|
||||
}
|
||||
|
||||
/** The Playwright `testDir`s the repository's `playwright*.config.ts` files name. */
|
||||
async function browserTestDirectories(root: string): Promise<string[]> {
|
||||
const configs = (await readdir(root).catch(() => [])).filter((name) =>
|
||||
/^playwright(?:\.[\w-]+)?\.config\.[cm]?[jt]s$/u.test(name),
|
||||
);
|
||||
const directories = await Promise.all(
|
||||
configs.map(async (config) =>
|
||||
/testDir:\s*["']\.?\/?([^"']+)["']/u.exec(await readFile(path.join(root, config), "utf8"))?.[1]
|
||||
?.replace(/\/$/u, ""),
|
||||
),
|
||||
);
|
||||
return directories.filter((directory): directory is string => directory !== undefined);
|
||||
}
|
||||
|
||||
export type FeatureRoutes = Readonly<{
|
||||
/** The removed feature's route paths. */
|
||||
paths?: readonly string[];
|
||||
/** Every route path left after the removal, platform routes included. */
|
||||
remainingPaths?: readonly string[];
|
||||
/** The removed feature's route IDs, platform IDs it took over left out. */
|
||||
ids?: readonly string[];
|
||||
}>;
|
||||
|
||||
export async function productFeatureResidue(
|
||||
root: string,
|
||||
featureId: string,
|
||||
directory: string,
|
||||
routes: FeatureRoutes = {},
|
||||
): Promise<string[]> {
|
||||
const names = [...new Set([featureId, directory])].map(escapeRegExp).join("|");
|
||||
const named = new RegExp(names, "iu");
|
||||
const nameSet = new Set([featureId, directory]);
|
||||
const names = [...nameSet].map(escapeRegExp).join("|");
|
||||
const wholeAnyName = featureNamePattern(featureId, directory);
|
||||
// A route ID left in platform source (a catalog key, `route.INVOICES_LIST`)
|
||||
// is found by its whole name too.
|
||||
const routeIds = [...new Set(routes.ids ?? [])].map(escapeRegExp);
|
||||
const wholeRouteId =
|
||||
routeIds.length === 0
|
||||
? null
|
||||
: new RegExp(`(?<![A-Za-z0-9_-])(?:${routeIds.join("|")})(?![A-Za-z0-9_-])`, "u");
|
||||
const pathNames = (relativePath: string) =>
|
||||
relativePath
|
||||
.split("/")
|
||||
.some((segment) => nameSet.has(segment) || nameSet.has(segment.split(".")[0] ?? ""));
|
||||
const imported = new RegExp(
|
||||
String.raw`(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\bmock\s*\(\s*)["'][^"'\n]*/features/(?:${names})/`,
|
||||
"u",
|
||||
@@ -70,20 +160,47 @@ export async function productFeatureResidue(
|
||||
specNames.length === 0
|
||||
? null
|
||||
: new RegExp(`(?<![A-Za-z0-9_-])(?:${specNames.join("|")})(?![A-Za-z0-9_-])`, "u");
|
||||
// A URL opens the route whose fixed prefix is the longest that fits it, so
|
||||
// a sibling feature's `/invoices/lines` in the same context is not the
|
||||
// removed `/invoices`. When a route left behind has the same prefix
|
||||
// (`/invoices` beside a removed `/invoices/:id`), the URL is not counted.
|
||||
const removed = prefixesOf(routes.paths ?? []);
|
||||
const remaining = prefixesOf(routes.remainingPaths ?? []);
|
||||
const candidates = [...new Set([...removed, ...remaining])].sort((a, b) => b.length - a.length);
|
||||
const opensRemovedRoute = (text: string) => {
|
||||
if (removed.size === 0) return false;
|
||||
for (const match of text.matchAll(/["'`](\/[^"'`\s]*)/gu)) {
|
||||
const best = candidates.find((prefix) => opens(match[1]!, prefix));
|
||||
if (best !== undefined && removed.has(best) && !remaining.has(best)) return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const browserDirectories = await browserTestDirectories(root);
|
||||
const playwrightSpec = /\.spec\.[cm]?[jt]sx?$/u;
|
||||
// A page object or helper beside the specs (`tests/e2e/support/*.ts`) runs
|
||||
// only in a browser too; a vitest test (`*.test.*`) does not.
|
||||
const browserFile = (name: string) =>
|
||||
playwrightSpec.test(name) ||
|
||||
(!/\.test\.[cm]?[jt]sx?$/u.test(name) &&
|
||||
browserDirectories.some((directory) => name.startsWith(`${directory}/`)));
|
||||
const residue: string[] = [];
|
||||
const relative = (file: string) => path.relative(root, file).split(path.sep).join("/");
|
||||
for (const file of await filesUnder(path.join(root, "src"))) {
|
||||
const name = relative(file);
|
||||
if (named.test(`${name}\n${await readFile(file, "utf8")}`)) residue.push(name);
|
||||
if (name.startsWith("src/.generated/")) continue;
|
||||
const text = await readFile(file, "utf8");
|
||||
if (pathNames(name) || wholeAnyName.test(text) || (wholeRouteId !== null && wholeRouteId.test(text))) {
|
||||
residue.push(name);
|
||||
}
|
||||
}
|
||||
for (const file of await filesUnder(path.join(root, "tests"))) {
|
||||
const name = relative(file);
|
||||
const text = await readFile(file, "utf8");
|
||||
if (
|
||||
named.test(name) ||
|
||||
pathNames(name) ||
|
||||
imported.test(text) ||
|
||||
(wholeName !== null && playwrightSpec.test(name) && wholeName.test(text))
|
||||
(playwrightSpec.test(name) && wholeName !== null && wholeName.test(text)) ||
|
||||
(browserFile(name) && opensRemovedRoute(text))
|
||||
) {
|
||||
residue.push(name);
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@ import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
import { namesOf } from "../create-feature.ts";
|
||||
import { localBuildEnvironment } from "./build-environment.ts";
|
||||
import { linkFixtureNodeModules } from "./fixture-node-modules.ts";
|
||||
import { REMOVAL_FIXTURE_COPY_TARGETS } from "./removal-fixture.ts";
|
||||
import { TEMPLATE_PROBE_PREFIX } from "./template-probe-features.ts";
|
||||
|
||||
/**
|
||||
* 2026-11-07. The template ships no feature. What needs one in a real build
|
||||
@@ -19,8 +21,19 @@ import { REMOVAL_FIXTURE_COPY_TARGETS } from "./removal-fixture.ts";
|
||||
* (scripts/scale/browser-soak.ts, `buildWithGeneratedFeature`). A change of
|
||||
* the generator's output fails there. The `--keyed` write slice is the widest
|
||||
* one the command makes.
|
||||
*
|
||||
* 1112/08-02. The id begins with the reserved probe prefix: the copy holds
|
||||
* the product's own features, and a product that had built `order-feature`
|
||||
* made create:feature refuse this one.
|
||||
*/
|
||||
export const GENERATED_FEATURE_ID = "order-feature";
|
||||
export const GENERATED_FEATURE_ID = `${TEMPLATE_PROBE_PREFIX}order-feature`;
|
||||
|
||||
const NAMES = namesOf(GENERATED_FEATURE_ID);
|
||||
|
||||
/** The key of one of the feature's words (`<camel>.list.title`). */
|
||||
export function generatedMessageKey(suffix: string): string {
|
||||
return `${NAMES.camel}.${suffix}`;
|
||||
}
|
||||
|
||||
export type GeneratedRoute = Readonly<{
|
||||
routeId: string;
|
||||
@@ -48,7 +61,7 @@ function node(root: string, args: readonly string[]): string {
|
||||
return result.stdout;
|
||||
}
|
||||
|
||||
/** The edit of a fixture build: `corepack pnpm create:feature order-feature --with-create --keyed`. */
|
||||
/** The edit of a fixture build: `corepack pnpm create:feature <GENERATED_FEATURE_ID> --with-create --keyed`. */
|
||||
export async function addGeneratedFeature(root: string): Promise<void> {
|
||||
node(root, ["scripts/generate-product-feature-index.ts"]);
|
||||
node(root, ["scripts/create-feature.ts", GENERATED_FEATURE_ID, "--with-create", "--keyed"]);
|
||||
@@ -62,23 +75,24 @@ export async function addGeneratedFeature(root: string): Promise<void> {
|
||||
export function generatedFeature(root: string): GeneratedFeature {
|
||||
const feature = path.join(root, "src/features", GENERATED_FEATURE_ID);
|
||||
const module = (file: string) => JSON.stringify(pathToFileURL(path.join(feature, file)).href);
|
||||
const { base, upper } = NAMES;
|
||||
const source = `
|
||||
const { ORDER_FEATURE_CONTRACT } = await import(${module("contracts/order-feature-contract.ts")});
|
||||
const { ORDER_MESSAGE_CATALOGS } = await import(${module("contracts/order-message-catalog.ts")});
|
||||
const { ORDER_LIST_ITEMS_CONTRACT } = await import(${module("contracts/order-contract-contribution.ts")});
|
||||
const { ${upper}_FEATURE_CONTRACT: CONTRACT } = await import(${module(`contracts/${GENERATED_FEATURE_ID}-contract.ts`)});
|
||||
const { ${upper}_MESSAGE_CATALOGS: CATALOGS } = await import(${module(`contracts/${base}-message-catalog.ts`)});
|
||||
const { ${upper}_LIST_ITEMS_CONTRACT: LIST_ITEMS } = await import(${module(`contracts/${base}-contract-contribution.ts`)});
|
||||
const { API_BASE_URL } = JSON.parse(await (await import("node:fs/promises")).readFile("config/runtime/local.json", "utf8"));
|
||||
const route = (id) => ({
|
||||
routeId: id,
|
||||
path: ORDER_FEATURE_CONTRACT.routes[id].path,
|
||||
chunkId: ORDER_FEATURE_CONTRACT.routes[id].chunkId,
|
||||
moduleId: ORDER_FEATURE_CONTRACT.routeRuntimeContracts[id].moduleId,
|
||||
path: CONTRACT.routes[id].path,
|
||||
chunkId: CONTRACT.routes[id].chunkId,
|
||||
moduleId: CONTRACT.routeRuntimeContracts[id].moduleId,
|
||||
});
|
||||
process.stdout.write(JSON.stringify({
|
||||
list: route("ORDER_LIST"),
|
||||
detail: route("ORDER_DETAIL"),
|
||||
create: route("ORDER_CREATE"),
|
||||
messages: ORDER_MESSAGE_CATALOGS,
|
||||
api: new URL(ORDER_LIST_ITEMS_CONTRACT.contract.pathTemplate.slice(1), API_BASE_URL).href,
|
||||
list: route("${upper}_LIST"),
|
||||
detail: route("${upper}_DETAIL"),
|
||||
create: route("${upper}_CREATE"),
|
||||
messages: CATALOGS,
|
||||
api: new URL(LIST_ITEMS.contract.pathTemplate.slice(1), API_BASE_URL).href,
|
||||
}));
|
||||
`;
|
||||
return JSON.parse(node(root, ["--input-type=module", "-e", source])) as GeneratedFeature;
|
||||
|
||||
@@ -3,6 +3,8 @@ import { mkdtemp, readFile, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { declaredCspProblems } from "./csp-policy.ts";
|
||||
|
||||
type ScanResult = Readonly<{
|
||||
error?: Error;
|
||||
status: number | null;
|
||||
@@ -168,3 +170,25 @@ export async function checkNonmatchingSecurityIncludeFixture(
|
||||
await cleanup(directory);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 0929/13-04. The policy check check:browser-security runs rejects its
|
||||
* fixture (a keyword in another case, in the first of two script-src) and
|
||||
* accepts the declared policy.
|
||||
*/
|
||||
export async function checkDeclaredCspFixtures(): Promise<void> {
|
||||
const fixture = "tests/fixtures/security/csp/rejected-security-headers.json";
|
||||
const rejected = declaredCspProblems(await readFile(fixture, "utf8"));
|
||||
const expected = ["script-src allows 'unsafe-inline'"];
|
||||
if (JSON.stringify(rejected) !== JSON.stringify(expected)) {
|
||||
throw new Error(
|
||||
`${fixture}: expected ${expected.join(", ")}; received ${rejected.join(", ") || "no problem"}`,
|
||||
);
|
||||
}
|
||||
const declared = declaredCspProblems(
|
||||
await readFile("config/hosting/security-headers.json", "utf8"),
|
||||
);
|
||||
if (declared.length > 0) {
|
||||
throw new Error(`config/hosting/security-headers.json: ${declared.join("; ")}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import { namesOf } from "../create-feature.ts";
|
||||
|
||||
/**
|
||||
* 1112/08-02. Feature ids the template's own tests and drills create in a
|
||||
* copy of the repository. The copy holds the product's features, and
|
||||
* create:feature refuses an id a feature there already has, or one with the
|
||||
* same prefix. A template test that used the manual's example
|
||||
* (`invoice-feature`) or a plain business word (`order-feature`) therefore
|
||||
* failed FE-GATE-005 and FE-GATE-008 in every product that had built a
|
||||
* feature by that name. Each id here begins with the prefix the template
|
||||
* reserves for its probes; docs/manual/reference/create-feature.md tells a
|
||||
* product not to use it.
|
||||
*/
|
||||
export const TEMPLATE_PROBE_PREFIX = "typecheck-probe-";
|
||||
|
||||
/** The feature the manual's code blocks are written for (docs/manual/01-add-a-feature.md). */
|
||||
export const MANUAL_EXAMPLE_FEATURE_ID = "invoice-feature";
|
||||
/** What tests/unit/manual-code-blocks.test.ts creates and renames the blocks to. */
|
||||
export const MANUAL_PROBE_FEATURE_ID = `${TEMPLATE_PROBE_PREFIX}${MANUAL_EXAMPLE_FEATURE_ID}`;
|
||||
/** The sample tests/unit/template-feature-removal-documents.test.ts lists and deletes. */
|
||||
export const LISTED_SAMPLE_PROBE_FEATURE_ID = `${TEMPLATE_PROBE_PREFIX}listed-sample-feature`;
|
||||
/** What FE-GATE-020's scaffold drill (scripts/test-feature-scaffold.ts, test:sample-removal) creates. */
|
||||
export const SCAFFOLD_PROBE_FEATURE_ID = `${TEMPLATE_PROBE_PREFIX}scaffold-feature`;
|
||||
/** The scaffold drill's `--with-create --keyed` feature. */
|
||||
export const SCAFFOLD_WRITE_PROBE_FEATURE_ID = `${TEMPLATE_PROBE_PREFIX}scaffold-write-feature`;
|
||||
|
||||
function escape(text: string): string {
|
||||
return text.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
||||
}
|
||||
|
||||
/**
|
||||
* `text` written for feature `fromId`, with every spelling create:feature
|
||||
* derives from an id (`INVOICE_`, `Invoice`, `invoice-`, `invoice`) moved to
|
||||
* the spelling it derives from `toId`. Prose that uses the word moves too;
|
||||
* what matters is that the names a block defines and the names it imports
|
||||
* from the generated feature move together.
|
||||
*/
|
||||
export function renameFeatureText(text: string, fromId: string, toId: string): string {
|
||||
const from = namesOf(fromId);
|
||||
const to = namesOf(toId);
|
||||
const spellings = new Map<string, string>([
|
||||
[from.upper, to.upper],
|
||||
[from.pascal, to.pascal],
|
||||
[`${from.base}-`, `${to.base}-`],
|
||||
[from.camel, to.camel],
|
||||
]);
|
||||
const pattern = new RegExp([...spellings.keys()].map(escape).join("|"), "gu");
|
||||
return text.replace(pattern, (match) => spellings.get(match) ?? match);
|
||||
}
|
||||
@@ -16,6 +16,15 @@ import { reachablePackageScripts } from "./package-script-graph.ts";
|
||||
export const UNGATED_TESTS_PATH = "config/ci/ungated-tests.json";
|
||||
|
||||
const TEST_FILE = /\.(?:test|spec)\.tsx?$/u;
|
||||
// vitest.config.ts includes only the `*.test.ts` and `*.test.tsx` files below tests.
|
||||
const VITEST_TEST_FILE = /\.test\.tsx?$/u;
|
||||
|
||||
/**
|
||||
* 0929/12-06. A gated path and the runner that reaches it. A Vitest path
|
||||
* runs its `*.test.*` files only; a Playwright `testDir` runs what the
|
||||
* Playwright default `testMatch` takes, `*.spec.*` and `*.test.*`.
|
||||
*/
|
||||
export type GatedTestTarget = Readonly<{ path: string; runner: "vitest" | "playwright" }>;
|
||||
|
||||
const ungatedTestsSchema = z
|
||||
.object({
|
||||
@@ -54,14 +63,26 @@ export function gatedTestPaths(
|
||||
entryScripts: readonly string[],
|
||||
readConfig: (file: string) => string,
|
||||
): string[] {
|
||||
const paths = new Set<string>();
|
||||
return [...new Set(gatedTestTargets(scripts, entryScripts, readConfig).map(({ path: target }) => target))].sort();
|
||||
}
|
||||
|
||||
export function gatedTestTargets(
|
||||
scripts: Readonly<Record<string, string>>,
|
||||
entryScripts: readonly string[],
|
||||
readConfig: (file: string) => string,
|
||||
): GatedTestTarget[] {
|
||||
const targets = new Map<string, GatedTestTarget>();
|
||||
const add = (target: string, runner: GatedTestTarget["runner"]) => {
|
||||
const normalized = target.replace(/\/$/u, "");
|
||||
targets.set(`${runner} ${normalized}`, { path: normalized, runner });
|
||||
};
|
||||
const addVitestPaths = (tokens: readonly string[]) => {
|
||||
const vitestRun = tokens.findIndex(
|
||||
(token, index) => token === "run" && /(?:run-vitest\.ts|vitest)$/u.test(tokens[index - 1] ?? ""),
|
||||
);
|
||||
if (vitestRun < 0) return;
|
||||
for (const token of tokens.slice(vitestRun + 1)) {
|
||||
if (!token.startsWith("-")) paths.add(token.replace(/\/$/u, ""));
|
||||
if (!token.startsWith("-")) add(token, "vitest");
|
||||
}
|
||||
};
|
||||
for (const script of reachablePackageScripts(scripts, entryScripts)) {
|
||||
@@ -79,20 +100,30 @@ export function gatedTestPaths(
|
||||
const configFlag = tokens.indexOf("--config");
|
||||
const config = configFlag >= 0 ? tokens[configFlag + 1]! : "playwright.config.ts";
|
||||
const testDir = /testDir:\s*["']\.?\/?([^"']+)["']/u.exec(readConfig(config))?.[1];
|
||||
if (testDir) paths.add(testDir.replace(/\/$/u, ""));
|
||||
if (testDir) add(testDir, "playwright");
|
||||
}
|
||||
}
|
||||
}
|
||||
return [...paths].sort();
|
||||
return [...targets.values()].sort(
|
||||
(left, right) => left.path.localeCompare(right.path) || left.runner.localeCompare(right.runner),
|
||||
);
|
||||
}
|
||||
|
||||
export function ungatedTestFailures(input: Readonly<{
|
||||
testFiles: readonly string[];
|
||||
gatedPaths: readonly string[];
|
||||
/** A bare string is a Vitest path. */
|
||||
gatedPaths: readonly (string | GatedTestTarget)[];
|
||||
exclusions: readonly UngatedTestExclusion[];
|
||||
}>): string[] {
|
||||
const targets = input.gatedPaths.map((target): GatedTestTarget =>
|
||||
typeof target === "string" ? { path: target, runner: "vitest" } : target,
|
||||
);
|
||||
const gated = (file: string) =>
|
||||
input.gatedPaths.some((gatedPath) => file === gatedPath || file.startsWith(`${gatedPath}/`));
|
||||
targets.some(
|
||||
({ path: gatedPath, runner }) =>
|
||||
(file === gatedPath || file.startsWith(`${gatedPath}/`)) &&
|
||||
(runner === "playwright" || VITEST_TEST_FILE.test(file)),
|
||||
);
|
||||
const excluded = new Set(input.exclusions.map(({ path: file }) => file));
|
||||
const failures = input.testFiles
|
||||
.filter((file) => !gated(file) && !excluded.has(file))
|
||||
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
type ProviderGuardianLease,
|
||||
} from "./lib/provider-guardian-client.ts";
|
||||
import { createProviderOutputLimiter } from "./lib/provider-output-limiter.ts";
|
||||
import { findProviderSandboxNamespaceFailure } from "./check-system-test-prerequisites.ts";
|
||||
import { PROVIDER_SANDBOX_NAMESPACE_ARGUMENTS } from "./lib/provider-sandbox-namespaces.ts";
|
||||
import {
|
||||
providerProcessTraceEnvironment,
|
||||
@@ -125,6 +126,13 @@ await access("/usr/bin/systemd-run", constants.X_OK).catch(() => {
|
||||
await access("/usr/bin/systemctl", constants.X_OK).catch(() => {
|
||||
throw new Error("provider cgroup unavailable: /usr/bin/systemctl is required");
|
||||
});
|
||||
// 1101/13-03. A runner that refuses the sandbox's unprivileged user and
|
||||
// network namespaces fails here, by name and with its host settings, instead
|
||||
// of later with bwrap's raw error.
|
||||
const namespaceFailure = await findProviderSandboxNamespaceFailure();
|
||||
if (namespaceFailure !== undefined) {
|
||||
throw new Error(`provider sandbox unavailable: ${namespaceFailure}`);
|
||||
}
|
||||
await assertProviderCgroupManagerAvailable();
|
||||
const trust = await readProviderTrust(workspaceRoot, publicKeyPath, keyId);
|
||||
if (!trust) throw new TypeError("provider supervisor trust key is invalid");
|
||||
|
||||
+12
-1
@@ -11,6 +11,7 @@ import {
|
||||
import { classifyGateStepResult } from "./lib/ci-step-result.ts";
|
||||
import { withCiGatePreflight } from "./contracts/ci-gates.ts";
|
||||
import { validateCiArtifact } from "./lib/ci-artifact-validator.ts";
|
||||
import { formatGateFailure } from "./lib/ci-gate-failure.ts";
|
||||
import { writeCiGateLogAtomic } from "./lib/ci-gate-log.ts";
|
||||
|
||||
const requestedGateId = process.argv
|
||||
@@ -111,6 +112,7 @@ for (const variable of gate.requiresEnvironment ?? []) {
|
||||
}
|
||||
}
|
||||
|
||||
let failedCommand: string | undefined;
|
||||
if (passed) {
|
||||
for (const commandId of gate.commandIds) {
|
||||
const step = contractIndex.commands.get(commandId);
|
||||
@@ -174,6 +176,7 @@ if (passed) {
|
||||
});
|
||||
if (!appendOutput(`classification: ${classification.kind}`)) passed = false;
|
||||
if (!classification.expectationMet) {
|
||||
failedCommand = commandLine;
|
||||
appendOutput(
|
||||
`expectation failed: expected ${step.expect}, exit=${result.status}, signal=${result.signal ?? "none"}`,
|
||||
...(step.expect === "fail"
|
||||
@@ -241,7 +244,15 @@ if (passed) {
|
||||
}
|
||||
|
||||
if (!passed) {
|
||||
process.stderr.write(`${gateId} ${gate.name}: FAIL\n`);
|
||||
process.stderr.write(
|
||||
`${formatGateFailure({
|
||||
gateId,
|
||||
gateName: gate.name,
|
||||
logPath: logArtifact.path,
|
||||
failedCommand,
|
||||
output,
|
||||
})}\n`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
process.stdout.write(
|
||||
|
||||
@@ -4,6 +4,10 @@ import { mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import { loadCiGateContract } from "./contracts/ci-gates.ts";
|
||||
import {
|
||||
SCAFFOLD_PROBE_FEATURE_ID,
|
||||
SCAFFOLD_WRITE_PROBE_FEATURE_ID,
|
||||
} from "./lib/template-probe-features.ts";
|
||||
import {
|
||||
runScaffoldDrillCommand,
|
||||
scaffoldDrillCommands,
|
||||
@@ -37,9 +41,10 @@ import {
|
||||
* test:sample-removal repeats the generation after deleting the sample
|
||||
* (decision 4), which proves the command needs nothing from it.
|
||||
*/
|
||||
const FEATURE_ID = "scaffold-feature";
|
||||
/** 1112/08-02. Reserved probe ids: the copy holds the product's own features. */
|
||||
const FEATURE_ID = SCAFFOLD_PROBE_FEATURE_ID;
|
||||
/** 1103/09-06. The `--with-create --keyed` slice, in its own context. */
|
||||
const WRITE_FEATURE_ID = "scaffold-write-feature";
|
||||
const WRITE_FEATURE_ID = SCAFFOLD_WRITE_PROBE_FEATURE_ID;
|
||||
const REPORT = "artifacts/tests/feature-scaffold.xml";
|
||||
|
||||
const pnpmCli = requireRemovalFixtureEnvironment("npm_execpath");
|
||||
|
||||
@@ -10,10 +10,11 @@ import { spawnSync } from "node:child_process";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { ROUTE_FEATURE_OWNER } from "../src/features/installed-feature-contracts.ts";
|
||||
import { PLATFORM_ROUTE_REGISTRY } from "../src/contracts/routes.ts";
|
||||
import { ROUTE_FEATURE_OWNER, routePath } from "../src/features/installed-feature-contracts.ts";
|
||||
import { loadCiGateContract } from "./contracts/ci-gates.ts";
|
||||
import { createFileSystemDeclarationSource } from "./generate-product-feature-index.ts";
|
||||
import { productFeatureResidue } from "./lib/feature-residue.ts";
|
||||
import { featureNamePattern, type FeatureRoutes, productFeatureResidue } from "./lib/feature-residue.ts";
|
||||
import { isProductionModulePath } from "./lib/risk-coverage.ts";
|
||||
import {
|
||||
createRemovalFixtureRoot,
|
||||
@@ -33,6 +34,7 @@ import {
|
||||
} from "./lib/removal-fixture.ts";
|
||||
import { REMOVAL_DRILL_SUITES_OUTSIDE_COVERAGE } from "./lib/feature-scaffold-drill.ts";
|
||||
import { REMOVABLE_TEMPLATE_FEATURES } from "./lib/removable-template-features.ts";
|
||||
import { SCAFFOLD_PROBE_FEATURE_ID } from "./lib/template-probe-features.ts";
|
||||
|
||||
/**
|
||||
* 09-07 (D-10). Removes one installed feature, `--feature=<id>`, from a copy
|
||||
@@ -163,6 +165,22 @@ const located = await locateFeature(featureId);
|
||||
const featureRouteIds = Object.entries(ROUTE_FEATURE_OWNER)
|
||||
.filter(([, owner]) => owner === featureId)
|
||||
.map(([routeId]) => routeId);
|
||||
// 0925 FOLLOW-UP 09-07. A browser test that opens the feature by one of these
|
||||
// paths is residue (scripts/lib/feature-residue.ts). A platform route the
|
||||
// feature took over (its home) goes back to the platform with the removal.
|
||||
const platformRoutePaths = new Set<string>(
|
||||
Object.values(PLATFORM_ROUTE_REGISTRY).map((route) => route.path),
|
||||
);
|
||||
const featureRoutes: FeatureRoutes = Object.freeze({
|
||||
paths: featureRouteIds.map(routePath).filter((candidate) => !platformRoutePaths.has(candidate)),
|
||||
remainingPaths: [
|
||||
...platformRoutePaths,
|
||||
...Object.keys(ROUTE_FEATURE_OWNER)
|
||||
.filter((routeId) => !featureRouteIds.includes(routeId))
|
||||
.map(routePath),
|
||||
],
|
||||
ids: featureRouteIds.filter((routeId) => !Object.hasOwn(PLATFORM_ROUTE_REGISTRY, routeId)),
|
||||
});
|
||||
|
||||
const fixtureRoot = await createRemovalFixtureRoot(`${featureId}-removal`);
|
||||
const pnpmCli = requireRemovalFixtureEnvironment("npm_execpath");
|
||||
@@ -454,11 +472,17 @@ try {
|
||||
|
||||
// 1105/16-04. Template tests use example feature IDs as data; only what
|
||||
// still points at the removed feature counts (scripts/lib/feature-residue.ts).
|
||||
const residue = await productFeatureResidue(fixtureRoot, featureId, located.directory);
|
||||
const builtResiduePattern = new RegExp(
|
||||
`${escapeRegExp(featureId)}|${escapeRegExp(located.directory)}`,
|
||||
"i",
|
||||
// 0925 FOLLOW-UP 09-07. The drill runs no Playwright spec; one that still
|
||||
// opens the feature's URL is found here instead of in FE-GATE-008.
|
||||
const residue = await productFeatureResidue(
|
||||
fixtureRoot,
|
||||
featureId,
|
||||
located.directory,
|
||||
featureRoutes,
|
||||
);
|
||||
// 1105/16-04. The same whole-name rule as `src`: the template's bundle
|
||||
// holds `data-product-feature`, which a substring search counted.
|
||||
const builtResiduePattern = featureNamePattern(featureId, located.directory);
|
||||
|
||||
const missingCommonTests: string[] = [];
|
||||
for (const testPath of commonTestPaths) {
|
||||
@@ -534,7 +558,7 @@ try {
|
||||
// 1103/09-06. With the write slice (NEVER), which needs nothing from
|
||||
// the sample either.
|
||||
const created = check("scaffold-create-feature", "create:feature", [
|
||||
"scaffold-feature",
|
||||
SCAFFOLD_PROBE_FEATURE_ID,
|
||||
"--with-create",
|
||||
]);
|
||||
checks.push(created);
|
||||
|
||||
@@ -234,6 +234,30 @@ class TurnEndNudgeTest(RepositoryTestCase):
|
||||
self.bash(command)
|
||||
self.assertIsNone(self.stop())
|
||||
|
||||
def test_reading_verify_sh_or_a_dry_run_does_not_count(self) -> None:
|
||||
# 1112/08-09. Only a command that runs a desktop step clears the reminder.
|
||||
for command in ("scripts/verify.sh merge --dry-run",
|
||||
"sed -n 1,80p scripts/verify.sh && ls",
|
||||
"grep -n foo scripts/verify.sh config/ci/gates.json",
|
||||
"git log -- scripts/verify.sh docs/work",
|
||||
"ssh desktop 'cat /tmp/claude-gates/x/FE-GATE-005.log | grep vitest'"):
|
||||
with self.subTest(command=command):
|
||||
self.edit("src/domain/order.ts", "export const a = 5;\n")
|
||||
self.bash(command)
|
||||
self.assertIsNotNone(self.stop())
|
||||
|
||||
def test_a_wrapped_desktop_step_counts(self) -> None:
|
||||
for command in ("timeout 900 scripts/verify.sh exec --log x -- node scripts/run-vitest.ts run tests/unit/a.test.ts",
|
||||
"VERIFY_SNAPSHOT=1 scripts/verify.sh merge --log r9",
|
||||
# round9 confirm review: a shell that runs the script, and ssh options with a value.
|
||||
"bash scripts/verify.sh merge --log r9",
|
||||
"ssh -o BatchMode=yes desktop 'cd ~/workspace/x && corepack pnpm -s lint'",
|
||||
"ssh -p 22 desktop 'corepack pnpm -s lint'"):
|
||||
with self.subTest(command=command):
|
||||
self.edit("src/domain/order.ts", "export const a = 6;\n")
|
||||
self.bash(command)
|
||||
self.assertIsNone(self.stop())
|
||||
|
||||
def test_laptop_commands_and_other_hosts_do_not_count(self) -> None:
|
||||
for command in ("corepack pnpm lint", "ssh build-box 'corepack pnpm lint'", "scripts/verify.sh docs",
|
||||
"scripts/verify.sh hooks", "scripts/verify.sh gate FE-GATE-005 --on here",
|
||||
@@ -244,13 +268,22 @@ class TurnEndNudgeTest(RepositoryTestCase):
|
||||
self.assertIsNotNone(self.stop())
|
||||
|
||||
def test_files_the_laptop_checks_do_not_need_the_desktop(self) -> None:
|
||||
for path in (".claude/rules/x.md", "scripts/hooks/hooks.py", "scripts/tests/test_x.py", "CLAUDE.md",
|
||||
"docs/ledger/estimates.jsonl", "scripts/check-work-docs.py", "src/adapters/AGENTS.md",
|
||||
"src/features/CLAUDE.md"):
|
||||
for path in (".claude/settings.json", "scripts/hooks/hooks.py", "scripts/tests/test_x.py",
|
||||
"docs/ledger/estimates.jsonl", "scripts/check-work-docs.py"):
|
||||
self.repo.write(path, "x\n")
|
||||
run_event("post-edit", self.repo.payload(path))
|
||||
self.assertIsNone(self.stop())
|
||||
|
||||
def test_living_instruction_documents_need_the_desktop(self) -> None:
|
||||
# 1112/08-04. verify:documentation, a desktop gate, checks these documents too.
|
||||
for path in (".claude/rules/x.md", ".claude/skills/fe-x/SKILL.md", "CLAUDE.md",
|
||||
"src/adapters/AGENTS.md", "src/features/CLAUDE.md",
|
||||
# round9 confirm review: living module READMEs beside laptop-checked files.
|
||||
"scripts/hooks/README.md", "docs/ledger/README.md"):
|
||||
with self.subTest(path=path):
|
||||
self.edit(path, "x\n")
|
||||
self.assertIsNotNone(self.stop())
|
||||
|
||||
def test_a_new_edit_after_the_reminder_reminds_again(self) -> None:
|
||||
self.edit("src/domain/order.ts", "export const a = 4;\n")
|
||||
self.stop()
|
||||
|
||||
@@ -90,6 +90,45 @@ class StagePlanTest(unittest.TestCase):
|
||||
expected.append(" ".join(words))
|
||||
self.assertEqual([line.split(": ", 1)[1] for line in result.stdout.splitlines()], expected)
|
||||
|
||||
def test_parts_passes_a_negative_fixture_only_with_its_registered_diagnostic(self) -> None:
|
||||
# run-ci-gate.ts passes an expect=fail command only when it exits with its code and prints its
|
||||
# diagnostic. parts saw the exit code alone, so a checker broken into an unrelated exit 1 (a
|
||||
# TypeError) still counted as its negative fixture passing.
|
||||
contract = gates()
|
||||
commands = {c["id"]: c for c in contract["commands"]}
|
||||
gate = next(g for g in contract["gates"] if g["id"] == "FE-GATE-029")
|
||||
negatives = [commands[c] for c in gate["commandIds"] if commands[c].get("expect") == "fail"]
|
||||
self.assertTrue(any(c.get("expectedDiagnosticId") for c in negatives))
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
fake = Path(tmp) / "corepack"
|
||||
# Answers `corepack pnpm -s <script> ...args` as the contract registers that command:
|
||||
# pass commands exit 0, negative fixtures exit with their code and print DIAGNOSTIC_MODE.
|
||||
fake.write_text(f"""#!/usr/bin/env python3
|
||||
import json, os, sys
|
||||
script, args = sys.argv[3], sys.argv[4:]
|
||||
for command in json.load(open({str(REPO / "config/ci/gates.json")!r}))["commands"]:
|
||||
if command["script"] == script and command.get("args", []) == args:
|
||||
break
|
||||
else:
|
||||
sys.exit(97)
|
||||
if command.get("expect") != "fail":
|
||||
sys.exit(0)
|
||||
if os.environ["DIAGNOSTIC_MODE"] == "registered":
|
||||
print("checker refused the fixture:", command.get("expectedDiagnosticId", ""))
|
||||
else:
|
||||
print("TypeError: Cannot read properties of undefined")
|
||||
sys.exit(command.get("expectedExitCode", 1))
|
||||
""", encoding="utf-8")
|
||||
fake.chmod(0o755)
|
||||
env = {"PATH": f"{tmp}:{os.environ['PATH']}"}
|
||||
wrong = sh([str(VERIFY), "parts", "FE-GATE-029", "--on", "here"], cwd=REPO, check=False,
|
||||
env={**env, "DIAGNOSTIC_MODE": "unrelated"})
|
||||
self.assertEqual(wrong.returncode, 1, wrong.stdout + wrong.stderr)
|
||||
self.assertIn("diagnostic", wrong.stderr)
|
||||
right = sh([str(VERIFY), "parts", "FE-GATE-029", "--on", "here"], cwd=REPO, check=False,
|
||||
env={**env, "DIAGNOSTIC_MODE": "registered"})
|
||||
self.assertEqual(right.returncode, 0, right.stdout + right.stderr)
|
||||
|
||||
def test_arguments_after_the_separator_go_to_the_one_script_or_command_as_given(self) -> None:
|
||||
result = sh([str(VERIFY), "script", "test:sample-removal", "--dry-run", "--", "--feature=invoice-feature"],
|
||||
cwd=REPO)
|
||||
|
||||
@@ -131,7 +131,20 @@ if (liveTarget?.passed && !slotEmpty) {
|
||||
const fixture = await readDocument(
|
||||
"tests/fixtures/hosting/response-headers.json",
|
||||
);
|
||||
responses = responseHeaders(fixture.responses);
|
||||
// 0929/13-04. The fixture host answers with the declared security headers
|
||||
// wherever the fixture names none, so a policy change is one file. A value
|
||||
// the fixture names is compared like a host's answer.
|
||||
const declaredAnswer = Object.fromEntries(
|
||||
Object.entries(securityHeaders).map(([header, value]) => [header.toLowerCase(), value]),
|
||||
);
|
||||
responses = Object.fromEntries(
|
||||
Object.entries(responseHeaders(fixture.responses)).map(([surface, headers]) => [
|
||||
surface,
|
||||
recordValue(cacheSurfaces[surface]).securityHeaders === true
|
||||
? { ...declaredAnswer, ...headers }
|
||||
: headers,
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
const results: ProbeResult[] = [...probeResults];
|
||||
|
||||
+32
-8
@@ -70,7 +70,8 @@ elif kind == "scripts":
|
||||
command = commands[command_id]
|
||||
# \x1f between fields keeps an empty exit code a field; \x1e between the command's args.
|
||||
args = "\x1e".join(command.get("args", []))
|
||||
print(f'{command["script"]}\x1f{command.get("expect", "pass")}\x1f{command.get("expectedExitCode", "")}\x1f{args}')
|
||||
print(f'{command["script"]}\x1f{command.get("expect", "pass")}\x1f{command.get("expectedExitCode", "")}'
|
||||
f'\x1f{args}\x1f{command.get("expectedDiagnosticId", "")}')
|
||||
PY
|
||||
}
|
||||
|
||||
@@ -119,8 +120,18 @@ step() {
|
||||
start=$(date +%s)
|
||||
log=${VERIFY_STEP_LOGS:+$VERIFY_STEP_LOGS/$(printf '%s' "$name" | tr ' /:' '___').log}
|
||||
set +e
|
||||
if [ -n "$log" ]; then "$@" > "$log" 2>&1; else "$@"; fi
|
||||
rc=$?
|
||||
# STEP_CAPTURE: also keep the output in that file (run_parts reads a negative fixture's diagnostic).
|
||||
if [ -n "$log" ]; then
|
||||
"$@" > "$log" 2>&1
|
||||
rc=$?
|
||||
[ -z "${STEP_CAPTURE:-}" ] || cp "$log" "$STEP_CAPTURE"
|
||||
elif [ -n "${STEP_CAPTURE:-}" ]; then
|
||||
"$@" 2>&1 | tee "$STEP_CAPTURE"
|
||||
rc=${PIPESTATUS[0]}
|
||||
else
|
||||
"$@"
|
||||
rc=$?
|
||||
fi
|
||||
set -e
|
||||
echo "$name rc=$rc $(( $(date +%s) - start ))s" | tee -a "${VERIFY_SUMMARY:-/dev/null}"
|
||||
return "$rc"
|
||||
@@ -148,20 +159,33 @@ run_gates() {
|
||||
}
|
||||
|
||||
run_parts() {
|
||||
local gate=$1 failed=0 script expect code argtext rc args prefix
|
||||
local gate=$1 failed=0 script expect code argtext diagnostic rc args prefix capture
|
||||
[ "$DRY_RUN" = 1 ] || ci_env
|
||||
gates_json scripts "$gate" > /dev/null || { echo "verify: config/ci/gates.json에 없는 게이트: $gate" >&2; return 2; }
|
||||
prefix=$(host_prefix "$gate")
|
||||
while IFS=$'\x1f' read -r script expect code argtext; do
|
||||
while IFS=$'\x1f' read -r script expect code argtext diagnostic; do
|
||||
rc=0
|
||||
args=()
|
||||
# The command's args, as run-ci-gate.ts passes them (`pnpm <script> ...args`).
|
||||
[ -z "$argtext" ] || IFS=$'\x1e' read -r -a args <<< "$argtext"
|
||||
capture=""
|
||||
if [ "$expect" = fail ] && [ "$DRY_RUN" != 1 ]; then
|
||||
capture=$(mktemp)
|
||||
TMP_FILES+=("$capture")
|
||||
fi
|
||||
# shellcheck disable=SC2086
|
||||
step "$gate $script" $prefix corepack pnpm -s "$script" ${args[@]+"${args[@]}"} || rc=$?
|
||||
# expect=fail인 명령(음성 fixture)은 정해진 종료 코드로 실패해야 통과다.
|
||||
STEP_CAPTURE=$capture step "$gate $script" $prefix corepack pnpm -s "$script" ${args[@]+"${args[@]}"} || rc=$?
|
||||
# expect=fail인 명령(음성 fixture)은 run-ci-gate.ts처럼 정해진 종료 코드로 실패하고 정해진 진단 문구를
|
||||
# 출력해야 통과다. 종료 코드만 보면 엉뚱한 원인의 exit 1(깨진 검사기)도 통과로 센다.
|
||||
if [ "$expect" = fail ]; then
|
||||
[ "$DRY_RUN" = 1 ] || [ "$rc" = "${code:-1}" ] || failed=1
|
||||
[ "$DRY_RUN" = 1 ] && continue
|
||||
if [ "$rc" != "${code:-1}" ]; then
|
||||
echo "verify: $gate $script: expected exit ${code:-1}, got $rc" >&2
|
||||
failed=1
|
||||
elif [ -n "$diagnostic" ] && ! grep -qF -- "$diagnostic" "$capture"; then
|
||||
echo "verify: $gate $script: exit $rc without the registered diagnostic: $diagnostic" >&2
|
||||
failed=1
|
||||
fi
|
||||
elif [ "$rc" != 0 ]; then
|
||||
failed=1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user