diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37fe25ba..45d2a2a6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -103,11 +103,13 @@ jobs: # workflow nobody watches — running it per-PR puts the result in front of a # reviewer while the change is still open. # - # 🔴 NOTE: this REPORTS, it does not GATE. `main`'s required contexts are - # exactly `pins-vs-published` and `scaffold-currency` (no rulesets), so a red - # run here does not block a merge — `build-test` doesn't either. Adding this - # to the required contexts is the outstanding maintainer decision recorded in - # AGENTS.md item 11. + # 🔴 NOTE: this both reports AND gates. `main`'s required contexts are + # `pins-vs-published`, `scaffold-currency`, `build-test`, `ready-ack-runtime` + # and `template-page-vite` (no rulesets), so a red run here blocks the merge. + # That was a policy change made after this job landed — it did NOT gate when + # it shipped. Re-measure with + # `gh api repos/civitai/cli/branches/main/protection` before calling any job + # here a gate; see AGENTS.md item 11. # # -v so the run REPORTS its controls (an inert emitter and a naive ack are # driven through the same assertions and must be rejected) rather than just an diff --git a/AGENTS.md b/AGENTS.md index 2d01f4ab..21d262aa 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -161,9 +161,11 @@ func newWhoAmICmd() *cobra.Command { Items 1–3, 10 and 11 are deliberate mirrors of the platform (items 4 and 8 are deliberate *non*-mirrors); items 5–9 cover `civitai app metrics`, the CLI's only analytics read path; items 12–17 cover `civitai generate`, the CLI's only path -that **spends the user's money irreversibly**. The durable fix for the mirroring -is a server-side `civitai app validate` endpoint that calls the real -`BlockManifestValidator` — until that exists, vendoring is on purpose. +that **spends the user's money irreversibly**; item 18 covers the two checks +that tell an author their EXISTING app is missing the item-11 handshake. The +durable fix for the mirroring is a server-side `civitai app validate` endpoint +that calls the real `BlockManifestValidator` — until that exists, vendoring is +on purpose. The generate items pull in the opposite direction from the mirror items, and that is deliberate: `validate` mirrors the platform because a local answer is @@ -502,18 +504,18 @@ neither one's. thing that BUILDS an SDK-free template, and it asserts the ack survives bundling (Guard A pins the source tree; Vite output is what the platform serves). - 🔴 **REPORTING IS NOT GATING — no ready-ack check currently blocks a - merge.** Measured, not assumed, via + 🔴 **REPORTING VS GATING — measure it, never infer it from the job + existing.** These jobs now gate. Measured via `gh api repos/civitai/cli/branches/main/protection`: the required contexts - are exactly `pins-vs-published` and `scaffold-currency`, with no rulesets. - So `ready-ack-runtime`, `template-page-vite` and even `build-test` all - report and stop nothing. **Outstanding step:** adding `ready-ack-runtime` - (and arguably `build-test`) to the required contexts is what converts - reporting into gating. That is a repo-policy change touching every open - PR, so it is the maintainer's call and was deliberately not taken by the - agent that wrote this. Until it is, do not describe any of these jobs as a - gate — an earlier revision of this item, and of - `ready_ack_runtime_test.go`, claimed one "BLOCKS the merge". It was false. + are `pins-vs-published`, `scaffold-currency`, `build-test`, + `ready-ack-runtime` and `template-page-vite`, with no rulesets. That was a + deliberate repo-policy change made AFTER this item first shipped; until + then all of these reported and stopped nothing — including `build-test`, + so the suite itself did not gate. Re-measure before describing any job + here as a gate: an earlier revision of this item, and of + `ready_ack_runtime_test.go`, claimed one "BLOCKS the merge" while it did + not. That claim was false when written and is true now only because the + contexts were added — not because the job runs. If you add a template, add nothing — Guard A picks it up automatically and fails until `ReadyAckPath()` is set. - **`BLOCK_HELLO` now exists host-side, and the emitter deliberately does @@ -695,6 +697,129 @@ neither one's. `deps.downloadBlob = reader.DownloadPresigned`; if you ever see that wired to `DownloadFile`, it is a credential leak, not a cleanup. +18. **The ready-ack checks for EXISTING apps are two deliberately different + tiers, and neither is allowed to be a hard failure.** #206 fixed the + templates; every app scaffolded before `4018e2c` is still broken and nothing + told its author. These close that gap, and the tier split is the whole + design: + - **`internal/antipattern`'s `resize-iframe-page` rule is a GATE** (it fails + the scaffold-currency job), because it fires on a *literal that is present + in the file* — no inference. It adds a THIRD family to that denylist: not a + dead REST route, and not a dead TOOL (`deprecated-blocks-cli` already + covered that one), but a dead host MESSAGE — marked N/A for + `PageBlockHost` by `hostHandlerParity.ts`. + 🔴 **A message NAME needs tighter scoping than a route or a package name, + because it is far more quotable, and both devices were earned by a false + positive.** `Exts: codeExts` keeps it out of `.md`/`.txt`/`.json`, where + naming the message in a sentence or using it as a JSON handler-table key is + ordinary writing — unscoped, the rule flagged its own documentation, and + this repo's README plus both scaffold READMEs exist to say "don't post + RESIZE_IFRAME". And it matches only a MATCHING `'` or `"` pair — + deliberately not the backtick form (markdown), and not a mismatched pair, + which is not a string literal in any language. `What` reads "reference to", + not "postMessage of": the regex matches the quoted token anywhere in code + (a dispatch-table key, a comparison, a constant — all equally dead on a + page surface), and saying "postMessage" would be a claim the pattern does + not make. It also assumes a page surface rather than reading a manifest: + `Rule` is a per-line regex with no manifest context, and every template this + CLI ships declares `page`. A non-page template would need that assumption + revisited, not the rule deleted. + - 🔴 **`validate`'s page-without-ack check is a WARNING and must stay one** + (`internal/validate/readyack.go`). It is the mirror image of item 3's + reasoning: `lockfile.go` earns hard-error status because the platform + *provably* fails (`npm ci` dies), whereas this infers RUNTIME behaviour + from STATIC TEXT and there are correct projects it cannot read — an ack + from a bundled dependency, a framework wrapper, a code-split chunk, an + extension the scan does not open. Hard-failing on a heuristic is the + false-warning-at-a-correct-project failure item 10 spent four measured + corrections avoiding, and `--strict` already lets anyone who wants a gate + have one. + - 🔴 **The evidence is an EXACT SET OF PACKAGES THAT ACK — never the + `@civitai/` scope.** This is the claim an audit falsified, so it is stated + with its measurement. Of the six published first-party packages, exactly + ONE acks: `@civitai/blocks-react@0.39.0` + (`dist/internal/iframeTransport.js:311`, `this.dispatch('BLOCK_READY', …)`). + `@civitai/app-sdk@0.31.0` does **not** — 17 runtime `.js` files, zero + containing the literal, the only hits a `.d.ts` type and the README, and it + declares no dependencies so it cannot ack transitively either. + `@civitai/theme`, `@civitai/components`, `@civitai/components-react` and + `@civitai/cli` contain none at all. A scope test is therefore wrong for + FOUR of six, and wrong in the expensive direction: `theme` and `components` + are framework-agnostic CSS, exactly what a hand-written no-build page app + installs, so the check went **silent on a genuinely broken app** — verified + live by adding `@civitai/theme` to a `static` scaffold with + `civitai-host.js` deleted. + The predicate lives in `blockproto.PackageAcksReady` with the per-package + evidence, and is used by BOTH `internal/validate/readyack.go` and + `civitaiSDKDeps` in `ready_ack_contract_test.go` — one rule, one place, + because Guard A had the identical hole (a future template depending on + `@civitai/theme` would have been classified SDK-backed and excused from + shipping an emitter: a born-broken template passing its own guard). The + match is EXACT; a prefix or substring test accepts a sibling + (`@civitai/blocks-react-native`) or a fork, and that widening class is what + `TestAckingPackagePredicate` exists to pin. Adding a package there is a + claim about its RUNTIME code — verify against the tarball, not the README + or the types, and record the version. + - **Comments are stripped, and that is load-bearing rather than tidy.** Both + SDK-free templates carry a source comment reading "The ONE message a page + app must send is `BLOCK_READY`", and it SURVIVES deleting + `civitai-host.js` — so without the strip the check is inert on the exact + population it was written for. Measured both ways. `.md` is excluded from + the scan for the same reason: a README describing the handshake is not an + implementation of it. + 🔴 **HTML comment stripping is gated to MARKUP extensions, and an + unterminated ``) reScriptSrc = regexp.MustCompile(`(?is)`, + "app.js": `document.title = 'hi';`, + }, + wantWarn: true, + why: "this is exactly the #206 shape the check exists to find", + }, + { + name: "page app shipping the real emitter does not warn", + manifest: ackManifest(false), + files: map[string]string{ + "index.html": ``, + "civitai-host.js": realEmitter(), + "unrelated.txt": "BLOCK_READY", + "src/component.js": `export const x = 1;`, + }, + wantWarn: false, + }, + { + // 🔴 THE REGRESSION THAT WOULD HURT MOST. The SDK's IframeTransport + // acks internally and the literal never appears in src/, so a + // source-only check warns at EVERY correct page-money app. + name: "page app depending on @civitai/blocks-react does not warn", + manifest: ackManifest(true), + files: map[string]string{ + "package.json": `{"dependencies": {"react": "^19.0.0", "@civitai/blocks-react": "^0.39.0"}}`, + "index.html": ``, + "src/main.tsx": `import { BlockProvider } from '@civitai/blocks-react';`, + }, + wantWarn: false, + }, + { + name: "the acking dep counts from devDependencies too", + manifest: ackManifest(true), + files: map[string]string{ + "package.json": `{"devDependencies": {"@civitai/blocks-react": "^0.39.0"}}`, + "src/main.ts": `export const x = 1;`, + }, + wantWarn: false, + }, + { + name: "the acking dep counts from peerDependencies too", + manifest: ackManifest(true), + files: map[string]string{ + "package.json": `{"peerDependencies": {"@civitai/blocks-react": "^0.39.0"}}`, + "src/main.ts": `export const x = 1;`, + }, + wantWarn: false, + }, + { + // 🔴 THE FALSIFIED CLAIM. `@civitai/theme` is framework-agnostic CSS + // tokens and contains no BLOCK_READY at all (measured on 0.2.0), so a + // scope test silenced a genuinely broken app. Reproduced live on a + // `static` scaffold with the emitter deleted before this case existed. + name: "a non-acking @civitai package does NOT silence the check", + manifest: ackManifest(true), + files: map[string]string{ + "package.json": `{"dependencies": {"@civitai/theme": "^0.2.0", "@civitai/components": "^0.3.0"}}`, + "index.html": ``, + "app.js": `document.title = 'hi';`, + }, + wantWarn: true, + }, + { + // `@civitai/app-sdk@0.31.0` ships 17 runtime .js files and NONE posts + // BLOCK_READY — the only occurrences are a .d.ts type literal and the + // README, and it declares no dependencies, so it cannot be acking + // transitively. An app-sdk-only project genuinely does not ack. + name: "@civitai/app-sdk alone does NOT silence the check", + manifest: ackManifest(true), + files: map[string]string{ + "package.json": `{"dependencies": {"@civitai/app-sdk": "^0.31.0"}}`, + "index.html": ``, + "src/main.ts": `export const x = 1;`, + }, + wantWarn: true, + }, + { + // Prefix widening: a sibling package name that merely starts the + // same way makes no ack promise. + name: "a sibling of the acking package does NOT silence the check", + manifest: ackManifest(true), + files: map[string]string{ + "package.json": `{"dependencies": {"@civitai/blocks-react-native": "^1.0.0"}}`, + "index.html": ``, + "app.js": `document.title = 'hi';`, + }, + wantWarn: true, + }, + { + // Substring widening: a fork that merely CONTAINS the acking name. + name: "a re-scoped fork does NOT silence the check", + manifest: ackManifest(true), + files: map[string]string{ + "package.json": `{"dependencies": {"@myorg/@civitai/blocks-react": "^1.0.0"}}`, + "index.html": ``, + "app.js": `document.title = 'hi';`, + }, + wantWarn: true, + }, + { + // The dep gate must be about a package that ACKS, not about "has a + // package.json". Without this, adding any dependency would silence + // the check. + name: "a package.json with no acking dep still warns", + manifest: ackManifest(true), + files: map[string]string{ + "package.json": `{"dependencies": {"react": "^19.0.0", "react-dom": "^19.0.0"}}`, + "index.html": ``, + "src/main.jsx": `import App from './App';`, + }, + wantWarn: true, + }, + { + name: "a non-page app never warns", + manifest: nonPageManifest, + files: map[string]string{ + "index.html": ``, + "app.js": `document.title = 'hi';`, + }, + wantWarn: false, + why: "the ready contract pinned here is the PAGE host's", + }, + { + // An explicit null is not a page surface. Pins the `v != nil` half of + // declaresPage: a presence-only test passes every other case in this + // table, so without this the two halves are indistinguishable. + name: `an explicit "page": null does not warn`, + manifest: nullPageManifest, + files: map[string]string{ + "index.html": ``, + "app.js": `document.title = 'hi';`, + }, + wantWarn: false, + }, + { + // 🔴 The comment strip. Both shipped SDK-free templates carry this + // exact sentence in a source comment, and it SURVIVES deleting the + // emitter — so without stripping, the check is inert on the very + // apps it was written for. + name: "an ack named only in a comment warns", + manifest: ackManifest(false), + files: map[string]string{ + "index.html": ``, + "app.js": "// The ONE message a page app must send is `BLOCK_READY`; without it the host\n" + + "// shows a failure card.\ndocument.title = 'hi';\n", + }, + wantWarn: true, + }, + { + name: "an ack named only in an HTML comment warns", + manifest: ackManifest(false), + files: map[string]string{ + "index.html": "\n\n", + "app.js": `document.title = 'hi';`, + }, + wantWarn: true, + }, + { + name: "an ack described only in the README warns", + manifest: ackManifest(false), + files: map[string]string{ + "index.html": ``, + "app.js": `document.title = 'hi';`, + "README.md": "The host waits for a `BLOCK_READY` message before it will show your app.", + }, + wantWarn: true, + why: "docs are not an implementation; both scaffold READMEs describe the handshake", + }, + { + // outputDir is never read: it does not exist before the first build + // and is gitignored, so a hit there says nothing about what is + // submitted... and its ABSENCE must not be read as evidence either. + // The conventional build directories are skipped BY NAME, for cost. + // A stale `dist` therefore cannot supply ack evidence the source + // lacks — the one correctness benefit of skipping, and the reason + // the name list keeps these entries. + name: "an ack present only in dist/ warns", + manifest: ackManifest(true), + files: map[string]string{ + "package.json": `{"dependencies": {"react": "^19.0.0"}}`, + "index.html": ``, + "src/main.jsx": `import App from './App';`, + "dist/assets/x.js": `window.parent.postMessage({type:'BLOCK_READY',payload:{}},o)`, + }, + wantWarn: true, + }, + { + // 🔴 THE FALSIFIED CLAIM, HALF ONE. `outputDir` used to be skipped + // from the MANIFEST, which meant a perfectly valid `"outputDir": + // "src"` skipped the directory holding the emitter and warned at a + // correct project — reproduced live on a page-vite scaffold whose + // manifest had ZERO validation errors. Skipping is a cost decision, + // never a correctness one: for a presence check, scanning extra can + // only ADD evidence while skipping can only CREATE a false warning. + name: `"outputDir": "src" must not hide the emitter that lives there`, + manifest: ackManifestOut(true, "src"), + files: map[string]string{ + "package.json": `{"dependencies": {"react": "^19.0.0"}}`, + "index.html": ``, + "src/main.jsx": `import './civitai-host.js';`, + "src/civitai-host.js": realEmitter(), + }, + wantWarn: false, + }, + { + // 🔴 HALF TWO. `"outputDir": "."` resolved to the project root, so the + // manifest-driven skip removed the ENTIRE tree, `scanned == 0`, and a + // genuinely broken app was silenced. No skip rule may ever be able to + // remove the root: the list is applied to ENTRIES, never to the root + // the scanner was handed. + name: `"outputDir": "." must not skip the whole project`, + manifest: ackManifestOut(true, "."), + files: map[string]string{ + "package.json": `{"dependencies": {"react": "^19.0.0"}}`, + "index.html": ``, + "app.js": `document.title = 'hi';`, + }, + wantWarn: true, + }, + { + // A non-conventional output directory is now SCANNED. That is the + // accepted residual trade: a stale build under `public/` can retain + // an ack the source lost and silence the check. A false negative, + // deliberately preferred over false-warning at every project whose + // outputDir happens to hold source (Vite's `public/` is a SOURCE + // directory, which is what made this the realistic shape). + name: "a non-conventional outputDir is scanned rather than skipped", + manifest: ackManifestOut(true, "public"), + files: map[string]string{ + "package.json": `{"dependencies": {"react": "^19.0.0"}}`, + "index.html": ``, + "src/main.jsx": `import App from './App';`, + "public/app.js": `window.parent.postMessage({type:'BLOCK_READY',payload:{}},o)`, + }, + wantWarn: false, + }, + { + // 🔴 An unterminated `` in strings must not swallow what is + // between them either — the reason HTML stripping is gated to markup. + name: "a matched pair in .js strings does not eat the emitter", + manifest: ackManifest(false), + files: map[string]string{ + "index.html": ``, + "app.js": "var OPEN = '';\n", + }, + wantWarn: false, + }, + { + // A real HTML comment in a markup file must STILL be stripped — the + // positive control for the gate above. Without it, "don't strip HTML + // in .js" is indistinguishable from "don't strip HTML at all". + name: "an HTML comment in .html is still stripped", + manifest: ackManifest(false), + files: map[string]string{ + "index.html": "\n\n", + "app.js": `document.title = 'hi';`, + }, + wantWarn: true, + }, + { + // A block comment naming the message is still a comment. There was no + // /* */ fixture at all before. + name: "an ack named only in a /* */ block comment warns", + manifest: ackManifest(false), + files: map[string]string{ + "index.html": ``, + "app.js": "/*\n * We should post BLOCK_READY at some point.\n */\ndocument.title = 'hi';\n", + }, + wantWarn: true, + }, + { + name: "an ack in node_modules does not count", + manifest: ackManifest(true), + files: map[string]string{ + "package.json": `{"dependencies": {"react": "^19.0.0"}}`, + "src/main.jsx": `import App from './App';`, + "node_modules/dep/idx.js": `postMessage({type:'BLOCK_READY'})`, + }, + wantWarn: true, + }, + { + name: "an inline ack in index.html does not warn", + manifest: ackManifest(false), + files: map[string]string{ + "index.html": "", + }, + wantWarn: false, + }, + { + name: "an ack in a .vue single-file component does not warn", + manifest: ackManifest(true), + files: map[string]string{ + "package.json": `{"dependencies": {"vue": "^3.5.0"}}`, + "src/App.vue": "", + "package-x.txt": "ignored", + }, + wantWarn: false, + }, + { + // A URL inside a string must not be read as the start of a comment. + // The ack is on the SAME LINE as the URL on purpose: with quote + // handling defeated, the `//` in `https://` starts a line comment and + // swallows everything after it — including the ack. Split across two + // lines this case passes with the string handling deleted, which is + // how the first version of it left that branch unproven. + name: "a URL literal does not swallow the ack after it", + manifest: ackManifest(false), + files: map[string]string{ + "index.html": ``, + "app.js": "var docs = 'https://civitai.com/docs'; " + + "window.parent.postMessage({ type: 'BLOCK_READY', payload: {} }, o);\n", + }, + wantWarn: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + wantAckWarning(t, ackProject(t, tt.manifest, tt.files), tt.wantWarn) + if tt.why != "" { + t.Logf("%s — %s", tt.name, tt.why) + } + }) + } +} + +// TestReadyAckCannotObserve pins the early-outs. Each of these is a project the +// check cannot answer for, and "cannot answer" must produce NO finding rather +// than a guess — the false-warning-at-a-correct-project failure AGENTS.md item +// 10 exists to prevent. +func TestReadyAckCannotObserve(t *testing.T) { + t.Run("an unparseable package.json silences the check", func(t *testing.T) { + dir := ackProject(t, ackManifest(true), map[string]string{ + "package.json": `{"dependencies": {`, // truncated + "src/main.jsx": `import App from './App';`, + }) + wantAckWarning(t, dir, false) + }) + + t.Run("a directory holding only a manifest silences the check", func(t *testing.T) { + // Zero source files READ. A zero-hit scan over a zero-file tree says + // nothing about the app — it is the same observation a scanner wired to + // nothing would produce. + dir := ackProject(t, ackManifest(false), nil) + wantAckWarning(t, dir, false) + }) + + t.Run("a tree of only unscanned file types silences the check", func(t *testing.T) { + dir := ackProject(t, ackManifest(false), map[string]string{ + "README.md": "no code here", + "notes.txt": "nor here", + "logo.svg": "", + "styles.css": "body{}", + }) + wantAckWarning(t, dir, false) + }) + + t.Run("one scannable file is enough to conclude", func(t *testing.T) { + // The positive control for the two cases above: as soon as the scanner + // really reads a line of code, a missing ack IS a finding. Without this, + // "scanned == 0 means silence" is indistinguishable from silence always. + dir := ackProject(t, ackManifest(false), map[string]string{ + "README.md": "no code here", + "index.html": `