-
Notifications
You must be signed in to change notification settings - Fork 9.4k
feat(ci): promote the certain-exempt docs core to merge-queue trust #6047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PerishCode
wants to merge
9
commits into
main
Choose a base branch
from
ci/scope-optimization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eb9876f
feat(ci): promote the certain-exempt docs core to merge-queue trust
PerishCode 5d0f1a8
docs(ci): record the scope confidence methodology in specs/current/ci.md
PerishCode b56bc20
fix(ci): narrow certain-exempt fixture handling
723faea
fix(ci): pin the trae-cli consumption exception to the daemon-lane wi…
PerishCode 47f62d8
docs(ci): codify exception-precondition binding in the methodology
PerishCode 3682778
fix(ci): fold static paths in exempt consumption guard
6849e86
fix(ci): require exclusive daemon test wiring
7852a1e
fix(ci): recognize daemon pnpm selector forms
5935905
fix(ci): tokenize daemon workflow test commands
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| import { readFile, readdir } from "node:fs/promises"; | ||
| import path from "node:path"; | ||
| import ts from "typescript"; | ||
|
|
||
| import { CERTAIN_EXEMPT_EXACT, CERTAIN_EXEMPT_PREFIXES } from "./scopes.ts"; | ||
|
|
||
| // Guard for the certain-tier exempt core in `scripts/scopes.ts` (rule | ||
| // `certain-exempt-surface`; methodology in `specs/current/ci.md`). | ||
| // | ||
| // Boundary invariant: no source that a *skippable* merge-gate lane executes may | ||
| // consume a certain-exempt file. If that held false, a docs-only change could | ||
| // invalidate a lane the promoted rule tells the merge queue to skip. | ||
| // | ||
| // What "consumption" means here, at two precision levels: | ||
| // - a dot-relative literal (`../../docs/...`) that resolves from the file's | ||
| // repo location into the certain-exempt surface: flagged everywhere — it can | ||
| // only mean the repository surface. | ||
| // - a bare repo-relative literal (`docs/CHANGELOG`): flagged only in non-test | ||
| // sources. In tests, bare `docs/...` strings are overwhelmingly project | ||
| // fixture paths inside sandboxed workspaces (and Vitest's cwd is the package | ||
| // dir, so a bare relative read could not reach repository docs/ anyway); | ||
| // real repo consumption in source code is a repo-root-resolved config | ||
| // default, which this level catches. | ||
| // Template literals with substitutions are not statically resolvable and are | ||
| // out of scope. | ||
| // | ||
| // Deliberately outside the checked surface: | ||
| // - root `scripts/` — floor-owned code. Preflight and workspace unit tests are | ||
| // unconditionally armed on every plan, so floor checks may read the exempt | ||
| // surface (product neutrality validates docs/ prose on every run). | ||
| // - `apps/landing-page/` — it IS the exempt surface; landing-page CI owns it. | ||
|
|
||
| const repoRoot = path.resolve(import.meta.dirname, ".."); | ||
|
|
||
| const checkedRoots = ["apps", "packages", "tools", "e2e"] as const; | ||
|
|
||
| const skippedDirectoryNames = new Set([ | ||
| ".astro", | ||
| ".next", | ||
| ".od-data", | ||
| "dist", | ||
| "node_modules", | ||
| "out", | ||
| "reports", | ||
| "test-results", | ||
| "vendor", | ||
| ]); | ||
|
|
||
| const skippedRepositoryPrefixes = ["apps/landing-page/"]; | ||
|
|
||
| const checkedExtensions = new Set([".ts", ".tsx"]); | ||
|
|
||
| // File-level exceptions. Every entry must explain why the reference is not | ||
| // gate-lane consumption of exempt-file *content*; revisit the entry if the | ||
| // file's relationship to the exempt surface changes. | ||
| const allowedConsumers = new Map<string, string>([ | ||
| [ | ||
| "tools/release/src/release-note/prepare.ts", | ||
| "docs/CHANGELOG feeds release-note preparation, which runs only in release workflows; @open-design/tools-release tests run in no ci.yml lane", | ||
| ], | ||
| [ | ||
| "e2e/tests/scripts/scopes.test.ts", | ||
| "behavior fixtures for this very check: source snippets passed to the collector as data, never resolved or opened", | ||
| ], | ||
| ]); | ||
|
|
||
| type ConsumptionViolation = { | ||
| filePath: string; | ||
| lineNumber: number; | ||
| literal: string; | ||
| }; | ||
|
|
||
| function toRepositoryPath(filePath: string): string { | ||
| return path.relative(repoRoot, filePath).split(path.sep).join("/"); | ||
| } | ||
|
|
||
| function landsInCertainExemptSurface(repositoryPath: string): boolean { | ||
| return ( | ||
| CERTAIN_EXEMPT_PREFIXES.some((prefix) => repositoryPath.startsWith(prefix)) || | ||
| (CERTAIN_EXEMPT_EXACT as readonly string[]).includes(repositoryPath) | ||
| ); | ||
| } | ||
|
|
||
| export function isFixtureTolerantPath(repositoryPath: string): boolean { | ||
| return ( | ||
| /\.test\.tsx?$/.test(repositoryPath) || | ||
| repositoryPath.includes("/tests/") || | ||
| repositoryPath.startsWith("e2e/") | ||
| ); | ||
| } | ||
|
|
||
| function literalConsumesCertainExemptSurface(fromRepositoryPath: string, literal: string): boolean { | ||
| if (literal.startsWith("./") || literal.startsWith("../")) { | ||
| const resolved = path.posix.normalize(path.posix.join(path.posix.dirname(fromRepositoryPath), literal)); | ||
| return landsInCertainExemptSurface(resolved); | ||
| } | ||
| if (isFixtureTolerantPath(fromRepositoryPath)) return false; | ||
| return landsInCertainExemptSurface(literal); | ||
| } | ||
|
|
||
| export function collectCertainExemptConsumptionFromSource( | ||
| repositoryPath: string, | ||
| source: string, | ||
| ): ConsumptionViolation[] { | ||
| const sourceFile = ts.createSourceFile( | ||
| repositoryPath, | ||
| source, | ||
| ts.ScriptTarget.Latest, | ||
| true, | ||
| repositoryPath.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS, | ||
| ); | ||
| const violations: ConsumptionViolation[] = []; | ||
|
|
||
| const visit = (node: ts.Node): void => { | ||
| if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) { | ||
|
PerishCode marked this conversation as resolved.
Outdated
|
||
| if (literalConsumesCertainExemptSurface(repositoryPath, node.text)) { | ||
| violations.push({ | ||
| filePath: repositoryPath, | ||
| lineNumber: sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1, | ||
| literal: node.text, | ||
| }); | ||
| } | ||
| } | ||
| ts.forEachChild(node, visit); | ||
| }; | ||
|
|
||
| visit(sourceFile); | ||
| return violations; | ||
| } | ||
|
|
||
| async function collectCheckedFiles(directory: string): Promise<string[]> { | ||
| const entries = await readdir(directory, { withFileTypes: true }); | ||
| const files: string[] = []; | ||
|
|
||
| for (const entry of entries) { | ||
| const fullPath = path.join(directory, entry.name); | ||
| const repositoryPath = toRepositoryPath(fullPath); | ||
|
|
||
| if (entry.isDirectory()) { | ||
| if ( | ||
| skippedDirectoryNames.has(entry.name) || | ||
| entry.name.startsWith(".next-") || | ||
| skippedRepositoryPrefixes.some((prefix) => `${repositoryPath}/`.startsWith(prefix)) | ||
| ) { | ||
| continue; | ||
| } | ||
| files.push(...(await collectCheckedFiles(fullPath))); | ||
| continue; | ||
| } | ||
|
|
||
| if (entry.isFile() && checkedExtensions.has(path.extname(entry.name))) { | ||
| files.push(repositoryPath); | ||
| } | ||
| } | ||
|
|
||
| return files; | ||
| } | ||
|
|
||
| export async function checkCertainExemptConsumption(): Promise<boolean> { | ||
| const violations: ConsumptionViolation[] = []; | ||
|
|
||
| for (const root of checkedRoots) { | ||
| for (const repositoryPath of await collectCheckedFiles(path.join(repoRoot, root))) { | ||
| if (allowedConsumers.has(repositoryPath)) continue; | ||
| const source = await readFile(path.join(repoRoot, repositoryPath), "utf8"); | ||
| violations.push(...collectCertainExemptConsumptionFromSource(repositoryPath, source)); | ||
| } | ||
| } | ||
|
|
||
| if (violations.length > 0) { | ||
| console.error("Certain-exempt surface consumption found in gate-lane sources:"); | ||
| for (const violation of violations) { | ||
| console.error(`- ${violation.filePath}:${violation.lineNumber} \`${violation.literal}\``); | ||
| } | ||
| console.error( | ||
| "Certain-tier exempt files must stay unconsumed by skippable merge-gate lanes (see specs/current/ci.md). Move the dependency, or add a justified allowlist entry in scripts/check-certain-exempt-consumption.ts.", | ||
| ); | ||
| return false; | ||
| } | ||
|
|
||
| console.log("Certain-exempt consumption check passed: gate-lane sources do not read the certain-exempt surface."); | ||
| return true; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.