mirror of
https://github.com/motajs/template.git
synced 2026-10-21 23:00:29 +08:00
docs(09-22): 修订第 4 轮审查(jsDoc 基线门禁前移到 Task 1 提交前 / defaults 清单 fixture)
This commit is contained in:
parent
dd56f741bb
commit
539c651672
@ -30,7 +30,7 @@ must_haves:
|
||||
- "**构建范围与顺序不变(用户裁定 3 / 4 / D-93):** 只改构建脚本与其测试;**不改** `script/build-lib.ts`、`package.json`、`index.html`、`dev.md`、`src/**`、`public/**`、数据端/渲染端源码(`packages-user/**`、`packages/**`)、`vite.config.ts`、lockfile、`script/dev.ts`;**不改构建顺序**(准备 → 渲染端 → 数据端 → content → LICENSE);**不做特殊失败处理**(无 BLOCKED 分支、无 baseline / 范围门禁、无外部状态检查)。"
|
||||
- "**开发环境不受影响:** 修饰器删除插件 `apply: 'build'`(`pnpm dev` 仍保留装饰器,`script/dev.ts` 不改);插件 `enforce: 'pre'`,其 `transform` 早于 Vite 的 TS/JSX 转译。"
|
||||
- "**测试是必需产物:** 扩展 `script/build-plugin.test.ts`(新增 `describe`,不改动既有 `dataIsolationPlugin` 用例)并新增 `script/build-resource.test.ts`;每个 `it` 前一行注释(AGENTS.md);content 测试用临时 fixture 目录,不触碰 `src/content`。"
|
||||
- "**验证可运行且范围诚实(Nyquist):** 修饰器删除用「纯函数文本断言 + **对照式双装饰器**真实 `vite.build()`」双证——同一 fixture 必须**导出一个类**、两个方法分别带 `@shouldReplay('...')` 与 `@ignoreReplay('...')`、各自返回**不同**的唯一字面量(`mota_replay_probe` / `mota_ignore_probe`),且 `shouldReplay` / `ignoreReplay` **工厂函数只在 fixture 内本地定义、不得导出**(否则实验组也会保留名字,对照失效)。**对照构建** `plugins: []` 产物必须 `toContain('shouldReplay')`、`toContain('ignoreReplay')`、`toContain('mota_replay_probe')`、`toContain('mota_ignore_probe')` 且两个方法名都在;**实验构建**(带插件)必须 `not.toContain('shouldReplay')`、`not.toContain('ignoreReplay')`、`toContain('mota_replay_probe')`、`toContain('mota_ignore_probe')` 且两个方法名都在(缺任一侧即成空断言);另含字符串/注释不误删、`node_modules` 跳过。content 过滤以 fixture 行为测试证明(`defaults` 全量、清单引用保留、未引用剔除、无清单子文件夹全量、**根目录即使出现 `.list.jsonc` 也全量**、`.list.jsonc` 压缩去注释、jsonc 去注释)。另加真实 `src/content` 的「清单覆盖率」检查、按函数切片的结构门禁、`build-resource.ts` **与 `build-plugin.ts`** 的「既有注释零删除」git 门禁(以 `git show HEAD:<file>` 的注释行集合为基线逐行比对,**不依赖暂存状态**),以及 `script/build-*.ts` 范围内的 `eslint`。结构门禁只断言**行为与导出形态**(AST API 标记、`enforce` / `apply`、导入绑定与注入位置),不硬编码提议命名。所有 `node -e` 门禁**只用单引号字面量**(PowerShell 5.1 下 `\"` 会提前闭合字符串,实测确定性 SyntaxError)。命令一律 `cmd /c \"pnpm exec ...\"`(PowerShell 5.1 下裸 `pnpm` 会因 `pnpm.ps1` 的 `PSSecurityException` 失败)。"
|
||||
- "**验证可运行且范围诚实(Nyquist):** 修饰器删除用「纯函数文本断言 + **对照式双装饰器**真实 `vite.build()`」双证——同一 fixture 必须**导出一个类**、两个方法分别带 `@shouldReplay('...')` 与 `@ignoreReplay('...')`、各自返回**不同**的唯一字面量(`mota_replay_probe` / `mota_ignore_probe`),且 `shouldReplay` / `ignoreReplay` **工厂函数只在 fixture 内本地定义、不得导出**(否则实验组也会保留名字,对照失效)。**对照构建** `plugins: []` 产物必须 `toContain('shouldReplay')`、`toContain('ignoreReplay')`、`toContain('mota_replay_probe')`、`toContain('mota_ignore_probe')` 且两个方法名都在;**实验构建**(带插件)必须 `not.toContain('shouldReplay')`、`not.toContain('ignoreReplay')`、`toContain('mota_replay_probe')`、`toContain('mota_ignore_probe')` 且两个方法名都在(缺任一侧即成空断言);另含字符串/注释不误删、`node_modules` 跳过。content 过滤以 fixture 行为测试证明(`defaults` 全量(即使 `defaults/` 内出现 `.list.jsonc`)、清单引用保留、未引用剔除、无清单子文件夹全量、**根目录即使出现 `.list.jsonc` 也全量**、`.list.jsonc` 压缩去注释、jsonc 去注释)。另加真实 `src/content` 的「清单覆盖率」检查、按函数切片的结构门禁、`build-resource.ts` 的「既有注释零删除」git 门禁放在 **Task 2**、`build-plugin.ts` 的同口径门禁放在 **Task 1 提交前**(各自以 `git show HEAD:<file>` 的注释行集合为基线逐行比对,**不依赖暂存状态**;Task 1 的门禁额外自校验「基线不得已含新导出 `replayDecoratorPlugin`」,否则基线已被本任务的提交污染、门禁作废),以及 `script/build-*.ts` 范围内的 `eslint`。结构门禁只断言**行为与导出形态**(AST API 标记、`enforce` / `apply`、导入绑定与注入位置),不硬编码提议命名。所有 `node -e` 门禁**只用单引号字面量**(PowerShell 5.1 下 `\"` 会提前闭合字符串,实测确定性 SyntaxError)。命令一律 `cmd /c \"pnpm exec ...\"`(PowerShell 5.1 下裸 `pnpm` 会因 `pnpm.ps1` 的 `PSSecurityException` 失败)。"
|
||||
- "**命名须先获批(D-04):** OI-1(`removeReplayDecorators` / `replayDecoratorPlugin` / `name: 'mota-replay-decorator'`,以及新增的模块级常量 `REPLAY_DECORATORS`(目标装饰器名集合)/ `SCRIPT_EXTENSIONS`(`.ts` / `.tsx` 后缀集合)/ `NODE_MODULES_SEGMENT`(`node_modules` 路径判定))、OI-2(`LIST_FILE_NAME` / `DEFAULTS_DIRECTORY` / `readListNames` / `collectListedNames` / `isListedFile` / `processDirectory` 新增的 `isRoot` 参数)、OI-3(`script/build-resource.test.ts` 文件名)。未获批前不得落码。**若用户在 Task 0 指定了与提议不同的命名,必须先按新命名修订本计划(门禁命令、测试用例与 SUMMARY 关键字同步)并重新获批后执行**——门禁本身按行为、值标记与导出形态断言,不会自动跟随改名。"
|
||||
artifacts:
|
||||
- path: script/build-plugin.ts
|
||||
@ -42,7 +42,7 @@ must_haves:
|
||||
- path: script/build-resource.ts
|
||||
provides: "content 过滤:`LIST_FILE_NAME`(`.list.jsonc`)、`DEFAULTS_DIRECTORY`(`defaults`)、`readListNames`、`collectListedNames`、`isListedFile`;`processDirectory` 增加 `isRoot` 参数(`buildContent` 传根标记,**根目录永不按清单取舍**);有清单的目录内按清单保留文件、`defaults` 与无清单目录全量输出、`.list.jsonc` 始终压缩输出(命名待批准,OI-2)"
|
||||
- path: script/build-resource.test.ts
|
||||
provides: "**新增**行为测试:临时 fixture 验证根文件、**根目录即使存在 `.list.jsonc` 也全量输出**、`defaults/` 全量、`maps/` 与 `texture/` 与 `font/` 的清单保留/剔除、**无清单子文件夹全量**、`.list.jsonc` 压缩且剥离整行 `//` 注释(fixture 清单原文带注释)、`item.ts` 原样拷贝;每个 `it` 前一行注释(文件名待批准,OI-3)"
|
||||
provides: "**新增**行为测试:临时 fixture 验证根文件、**根目录即使存在 `.list.jsonc` 也全量输出**、`defaults/` 全量(**fixture 内 `defaults/.list.jsonc` 只列 `env`,`env.jsonc` 与 `other.jsonc` 仍都输出**,镜像根目录用例)、`maps/` 与 `texture/` 与 `font/` 的清单保留/剔除、**无清单子文件夹全量**、`.list.jsonc` 压缩且剥离整行 `//` 注释(fixture 清单原文带注释)、`item.ts` 原样拷贝;每个 `it` 前一行注释(文件名待批准,OI-3)"
|
||||
- path: .planning/phases/09-minimum-browser-runnable/09-22-SUMMARY.md
|
||||
provides: "执行摘要:content 逐文件夹过滤规则与清单匹配口径、修饰器删除口径(TS AST + 双端注入 + 不删 import)、命名获批情形、门禁结果、`open_items` 处置、已知边界(未端到端跑全量 `build:game`;生产产物不再做录像安全检查;`index.html` 仍引用 `/styles.css`)"
|
||||
key_links:
|
||||
@ -156,7 +156,7 @@ Phase 9 · 任务 11 · 第 22 个计划 —— **构建脚本的 content 过滤
|
||||
|
||||
④ **修饰器删除口径(用户裁定 2):** 构建时删除**所有** `@shouldReplay(...)` / `@ignoreReplay(...)` 应用(当前 `@shouldReplay` = **69 次应用 / 20 个 `.ts` 文件**;`packages-user/data-common/src/replay/func.ts` 另有 1 行注释含 2 处 `@shouldReplay` 文本,非应用;`@ignoreReplay` 无实际应用),**数据端与渲染端都删**(`buildData` + `buildClient` 各注入一次);用 **TypeScript AST**(`ts.createSourceFile` + `ts.canHaveDecorators` / `ts.getDecorators`)取装饰器节点范围后**逆序切片删除**,字符串 / 注释中的同名文本不删;仅处理项目自身 `.ts` / `.tsx`,跳过 `node_modules`,不处理 `.vue`;**不手动删 import**(交给依赖分析 tree-shaking)。插件 `apply: 'build'`,故 `pnpm dev` 行为不变。
|
||||
|
||||
⑤ **验证方式:** `script/build-plugin.test.ts` 扩展为「纯函数断言(删装饰器、字符串/注释不误删、带引号与括号的参数整段删除)+ **对照式双装饰器**真实 `vite.build()`(同一 fixture 构建两次:fixture **导出一个类**,两个方法分别带 `@shouldReplay` / `@ignoreReplay` 并各自返回不同唯一字面量 `mota_replay_probe` / `mota_ignore_probe`,`shouldReplay` / `ignoreReplay` 工厂在 fixture 内**本地定义、不导出**;**对照** `plugins: []` 产物必须含 `shouldReplay`、`ignoreReplay`、两个唯一字面量与两个方法名,**实验组**必须不含 `shouldReplay` / `ignoreReplay`,但两个唯一字面量与两个方法名**仍在**——两侧缺一即空断言)」;`script/build-resource.test.ts` 用临时 fixture 验证根文件、**根目录即使存在 `.list.jsonc` 也全量输出**、`defaults/` 全量、`maps` / `texture` / `font` 的保留与剔除、**无清单子文件夹全量**、`.list.jsonc` 压缩且剥离整行 `//` 注释、`item.ts` 原样;另加真实 `src/content` 的清单覆盖率检查(每个清单目录内非清单文件都必须被清单命中,防止过滤掉现有素材)、`build-game` 按函数切片的结构门禁(只断言导入绑定与注入位置,不绑定提议命名)、`build-resource.ts` **与 `build-plugin.ts`** 的「既有注释零删除」门禁(从 `git show HEAD:<file>` 取注释行集合逐行比对,**不受暂存状态影响**,并校验基线注释行数下限防空洞),以及 `script/build-*.ts` 范围内的 `eslint`;命令一律 `cmd /c "pnpm exec ..."`,内联 `node -e` 只用单引号字面量。
|
||||
⑤ **验证方式:** `script/build-plugin.test.ts` 扩展为「纯函数断言(删装饰器、字符串/注释不误删、带引号与括号的参数整段删除)+ **对照式双装饰器**真实 `vite.build()`(同一 fixture 构建两次:fixture **导出一个类**,两个方法分别带 `@shouldReplay` / `@ignoreReplay` 并各自返回不同唯一字面量 `mota_replay_probe` / `mota_ignore_probe`,`shouldReplay` / `ignoreReplay` 工厂在 fixture 内**本地定义、不导出**;**对照** `plugins: []` 产物必须含 `shouldReplay`、`ignoreReplay`、两个唯一字面量与两个方法名,**实验组**必须不含 `shouldReplay` / `ignoreReplay`,但两个唯一字面量与两个方法名**仍在**——两侧缺一即空断言)」;`script/build-resource.test.ts` 用临时 fixture 验证根文件、**根目录即使存在 `.list.jsonc` 也全量输出**、`defaults/` 全量(即使 `defaults/` 内存在 `.list.jsonc`)、`maps` / `texture` / `font` 的保留与剔除、**无清单子文件夹全量**、`.list.jsonc` 压缩且剥离整行 `//` 注释、`item.ts` 原样;另加真实 `src/content` 的清单覆盖率检查(每个清单目录内非清单文件都必须被清单命中,防止过滤掉现有素材)、`build-game` 按函数切片的结构门禁(只断言导入绑定与注入位置,不绑定提议命名)、`build-resource.ts` 与 `build-plugin.ts` 的「既有注释零删除」门禁(各自从 `git show HEAD:<file>` 取注释行集合逐行比对,**不受暂存状态影响**,并校验基线注释行数下限防空洞;**`build-plugin.ts` 的门禁落在 Task 1 提交前**——基线若已含新导出即自失败,`build-resource.ts` 的门禁落在 Task 2),以及 `script/build-*.ts` 范围内的 `eslint`;命令一律 `cmd /c "pnpm exec ..."`,内联 `node -e` 只用单引号字面量。
|
||||
|
||||
⑥ **已知边界(原样告知):** ① **不端到端运行全量 `build:game`**(渲染端仍有用户 WIP 的 stale import;09-21 已记录),验证只到单测 + 结构门禁 + 真实清单覆盖率;② 生产构建不再有录像安全检查装饰器,属预期结果;③ `index.html` 仍引用 `/styles.css`,本计划不产出、不改;④ `animation` / `audio` / `font` 目录当前无对应素材(清单为空或无文件),过滤不会影响现有产物。
|
||||
|
||||
@ -256,6 +256,8 @@ Phase 9 · 任务 11 · 第 22 个计划 —— **构建脚本的 content 过滤
|
||||
<fails_when>non-zero exit,或任一断言失败(装饰器未被删 / 参数残留碎片 / 字符串或注释中的同名文本被误删 / 对照产物缺 `shouldReplay` 或 `ignoreReplay` 或某个唯一字面量(token 前提不成立)/ 带插件产物仍含 `shouldReplay` / `ignoreReplay` / 带插件产物丢了 `mota_replay_probe`、`mota_ignore_probe` 或方法名 / 既有 `dataIsolationPlugin` 用例回归)</fails_when>
|
||||
<automated>node -e "const fs=require('fs');const bad=[];const q=String.fromCharCode(39);const t=fs.readFileSync('script/build-plugin.ts','utf8');const need=['ts.createSourceFile','canHaveDecorators','getDecorators','node_modules','shouldReplay','ignoreReplay','dataIsolationPlugin','transform(','code: string','fileName: string','): string','): Plugin','enforce: '+q+'pre'+q,'apply: '+q+'build'+q];for(const x of need){if(t.indexOf(x)<0)bad.push('build-plugin.ts missing: '+x)}const exported=[...t.matchAll(/export function (\w+)/g)].map(m=>m[1]);if(exported.length<3)bad.push('build-plugin.ts must export dataIsolationPlugin plus two strip APIs, found '+exported.length);if(exported.indexOf('dataIsolationPlugin')<0)bad.push('dataIsolationPlugin export lost');const tp=fs.readFileSync('script/build-plugin.test.ts','utf8');for(const x of ['@shouldReplay','@ignoreReplay','node_modules','mota_replay_probe','mota_ignore_probe','export class','build(','not.toContain']){if(tp.indexOf(x)<0)bad.push('build-plugin.test.ts missing: '+x)}if(tp.indexOf('plugins: []')<0&&tp.indexOf('plugins:[]')<0)bad.push('test must include a control vite.build without the plugin');const cnt=(s,sub)=>s.split(sub).length-1;const pos='.toContain('+q,neg='.not.toContain('+q;for(const name of ['shouldReplay','ignoreReplay','mota_replay_probe','mota_ignore_probe']){if(cnt(tp,pos+name+q+')')-cnt(tp,neg+name+q+')')<1)bad.push('test must positively assert '+name+' in the control build')}for(const name of ['shouldReplay','ignoreReplay']){if(cnt(tp,neg+name+q+')')<1)bad.push('test must negatively assert '+name+' in the plugin build')}for(const fn of ['shouldReplay','ignoreReplay']){if(tp.indexOf('function '+fn+'(')<0)bad.push('fixture must locally define '+fn);if(tp.indexOf('export function '+fn)>-1)bad.push('fixture must NOT export '+fn)}const g=fs.readFileSync('script/build-game.ts','utf8');const s=g.indexOf('async function buildClient('),d=g.indexOf('async function buildData('),b=g.indexOf('async function buildGame(');if(s<0||d<0||b<0||!(s<d&&d<b))bad.push('function order changed; slicing gate needs buildClient < buildData < buildGame');else{const idx=g.indexOf('./build-plugin');if(idx<0)bad.push('build-game.ts must import from ./build-plugin');else{const start=g.lastIndexOf('import',idx),open=g.indexOf('{',start),close=g.indexOf('}',open);const bindings=g.slice(open+1,close).split(',').map(v=>v.trim()).filter(Boolean);const extra=bindings.filter(n=>n!=='dataIsolationPlugin');if(bindings.indexOf('dataIsolationPlugin')<0)bad.push('dataIsolationPlugin import lost');if(extra.length!==1)bad.push('exactly one new binding expected from ./build-plugin, got '+extra.length);else{const client=g.slice(s,d),data=g.slice(d,b);if(client.indexOf(extra[0])<0)bad.push('buildClient must inject the replay decorator plugin');if(data.indexOf(extra[0])<0)bad.push('buildData must inject the replay decorator plugin');if(data.indexOf('dataIsolationPlugin')<0)bad.push('buildData must keep dataIsolationPlugin');if(client.indexOf('dataIsolation'+'Plugin')>=0)bad.push('dataIsolationPlugin must stay out of buildClient')}}}if(bad.length>0){console.error('REPLAY PLUGIN GATE FAILED :: '+bad.join(' ; '));process.exit(1)}console.log('OK replay plugin: AST strip + dual-sided wiring')"</automated>
|
||||
<fails_when>non-zero exit,或 stderr 含 "REPLAY PLUGIN GATE FAILED"(插件缺 AST 定位(`ts.createSourceFile` / `canHaveDecorators` / `getDecorators`)/ 缺 `enforce: 'pre'` 或 `apply: 'build'` / 缺 `node_modules` 跳过 / 导出数少于 3 或丢了 `dataIsolationPlugin` / 缺 `code: string` + `fileName: string` + `): string` 或 `): Plugin` 导出形态 / 测试缺关键用例字样或 `mota_ignore_probe` / 测试缺 `export class` 形态 / 测试缺少不带插件的对照构建(`plugins: []`)/ 测试缺少对 `shouldReplay` / `ignoreReplay` / `mota_replay_probe` / `mota_ignore_probe` 的**正向**断言 / 测试缺少对 `shouldReplay` / `ignoreReplay` 的**负向**断言 / 测试导出了 `shouldReplay` 或 `ignoreReplay` 工厂(对照会失效)/ 函数定义顺序不满足切片前提 / `./build-plugin` 的导入绑定不是「`dataIsolationPlugin` + 恰好 1 个新插件」/ `buildClient` 或 `buildData` 片段缺该新插件 / `buildData` 丢了 `dataIsolationPlugin` / `dataIsolationPlugin` 被接进 `buildClient`)</fails_when>
|
||||
<automated>node -e "const fs=require('fs'),cp=require('child_process');const f='script/build-plugin.ts';const bad=[];let head='';try{head=cp.execSync('git show HEAD:'+f,{encoding:'utf8'})}catch(e){bad.push('cannot read HEAD version of '+f+': '+e.message)}if(head.indexOf('replayDecoratorPlugin')>-1)bad.push('baseline HEAD:'+f+' already contains replayDecoratorPlugin - this comment gate must run BEFORE this task commits');const marks=['//','/*','*'];const isComment=l=>marks.some(m=>l.startsWith(m));const baseSet=new Set(head.split(/\r?\n/).map(l=>l.trim()).filter(isComment));if(baseSet.size<5)bad.push(f+' baseline comment lines too few ('+baseSet.size+'<5), comment gate would be vacuous');const curSet=new Set(fs.readFileSync(f,'utf8').split(/\r?\n/).map(l=>l.trim()));const lost=[...baseSet].filter(l=>!curSet.has(l));if(lost.length>0)bad.push(f+' lost '+lost.length+' existing comment/jsDoc line(s), first: '+lost[0]);if(bad.length>0){console.error('PLUGIN COMMENT GATE FAILED :: '+bad.join(' ; '));process.exit(1)}console.log('OK plugin comments: HEAD-baseline comment lines intact ('+baseSet.size+' lines)')"</automated>
|
||||
<fails_when>non-zero exit,或 stderr 含 "PLUGIN COMMENT GATE FAILED":`git show HEAD:script/build-plugin.ts` 基线中的既有注释 / jsDoc 行在当前文件中缺失(被删除或改写)/ 基线注释行数低于下限 5(门禁可能空洞)/ 基线已含新导出 `replayDecoratorPlugin`——说明本门禁跑在本任务提交之后、基线已被污染,必须回退到提交前执行</fails_when>
|
||||
</verify>
|
||||
<acceptance_criteria>
|
||||
- `script/build-plugin.ts` 新增 `removeReplayDecorators` 与 `replayDecoratorPlugin`(命名按 OI-1 获批结果),`enforce: 'pre'` + `apply: 'build'`,仅处理项目内 `.ts` / `.tsx`,跳过 `node_modules`
|
||||
@ -263,10 +265,10 @@ Phase 9 · 任务 11 · 第 22 个计划 —— **构建脚本的 content 过滤
|
||||
- `script/build-game.ts` 在 `buildClient` 与 `buildData` 各注入一次;`buildData` 仍保持 `dataIsolationPlugin` 首位;构建顺序与其余配置未改
|
||||
- 既有 `dataIsolationPlugin` 的行为与用例零回归
|
||||
- `script/build-plugin.test.ts` 覆盖「删两类装饰器、参数含引号/括号、字符串不误删、注释不误删、`node_modules` 跳过、**对照式双装饰器** `vite.build()`(fixture 导出类 + 两个方法各带一种装饰器各返回唯一字面量 + 工厂本地不导出;`plugins: []` 对照产物含 `shouldReplay` / `ignoreReplay` / 两个唯一字面量 / 两个方法名,带插件产物不含 `shouldReplay` / `ignoreReplay` 但两个唯一字面量与两个方法名仍在)」;每个 `it` 前一行注释
|
||||
- 既有注释未被改写:`dataIsolationPlugin` / `SPECIFIER_BANS` / `PATH_BANS` / `findBan` 的注释逐字保留;新增 jsDoc 只出现在新函数上
|
||||
- 既有注释未被改写:`dataIsolationPlugin` / `SPECIFIER_BANS` / `PATH_BANS` / `findBan` 的注释逐字保留(由**本任务提交前**的 `git show HEAD:script/build-plugin.ts` 基线门禁证明;基线若已含新导出 `replayDecoratorPlugin` 即门禁自失败);新增 jsDoc 只出现在新函数上
|
||||
- 未手删任何 import;未改 `packages-user/**` / `packages/**` / `src/**` / `script/dev.ts`
|
||||
</acceptance_criteria>
|
||||
<done>修饰器删除插件就位并双端注入:数据端与渲染端构建都不再编译 `@shouldReplay` / `@ignoreReplay` 应用(AST 精确切片、字符串与注释无损伤、`node_modules` 跳过),对照构建证明 token 在未处理时确实存在,开发服务行为不变;单测与结构门禁全绿,既有隔离插件零回归</done>
|
||||
<done>修饰器删除插件就位并双端注入:数据端与渲染端构建都不再编译 `@shouldReplay` / `@ignoreReplay` 应用(AST 精确切片、字符串与注释无损伤、`node_modules` 跳过),对照构建证明 token 在未处理时确实存在,开发服务行为不变;单测、结构门禁与注释基线门禁全绿,既有隔离插件零回归</done>
|
||||
</task>
|
||||
<task type="auto" tdd="true">
|
||||
<name>Task 2: content 清单过滤(`script/build-resource.ts`)+ 行为测试 + SUMMARY</name>
|
||||
@ -300,7 +302,7 @@ Phase 9 · 任务 11 · 第 22 个计划 —— **构建脚本的 content 过滤
|
||||
(2) **新增 `script/build-resource.test.ts`(OI-3):** `mkdtemp` 建临时 fixture,`afterEach` 清理;每个 `it` 前一行注释:
|
||||
- **根目录 jsonc:** `core.jsonc` 含 `// Type: ...` 与系统标记行 → 输出同名 `.jsonc`,`JSON.parse` 成功、文本不含 `//`。
|
||||
- **根目录即使存在 `.list.jsonc` 也全量输出:** fixture 根放 `.list.jsonc`(内容 `["core"]`)+ `core.jsonc` + `other.jsonc` → `core.jsonc` 与 `other.jsonc` **都存在**(证明根目录 `isRoot` 跳过过滤,root 行为不依赖「当前根目录没有清单」这一现状)。
|
||||
- **`defaults/` 全量:** `defaults/env.jsonc` 含注释且不被任何清单引用 → 仍输出且已压缩。
|
||||
- **`defaults/` 全量(即使存在清单):** `defaults/` 内放 `.list.jsonc`(内容 `["env"]`)+ `env.jsonc`(含注释)+ `other.jsonc` → `env.jsonc` 与 `other.jsonc` **都输出**且已压缩、`.list.jsonc` 自身也已压缩输出(证明 `isDefaults` 豁免真实生效,不依赖「`defaults/` 当前恰好没有清单」这一现状;与根目录 `isRoot` 用例同构)。
|
||||
- **`maps/` 清单(fixture 清单原文带 `//` 注释):** `.list.jsonc` 写成「`// Type: string[], without .jsonc suffix` + `// --- SYSTEM PREFIX END --- //` + `["keep"]`」三部分,同目录放 `keep.jsonc` 与 `drop.jsonc` → `keep.jsonc` 输出、`drop.jsonc` **不存在**、`.list.jsonc` 输出且 `JSON.parse` 成功、输出文本**不含 `//`**(注释与系统标记行被剥离)。
|
||||
- **`texture/` 清单(对象形态 + 完整文件名):** `.list.jsonc` = `{"textures":[{"type":"grid","source":"a.png"}]}` + `a.png` + `b.png` → `a.png` 存在且与源字节一致、`b.png` 不存在。
|
||||
- **`font/` 清单:** `.list.jsonc` = `["ok.fake"]` + `ok.fake` + `skip.fake` → `ok.fake` 存在、`skip.fake` 不存在(用非字体扩展名避开 fontmin)。
|
||||
@ -313,7 +315,7 @@ Phase 9 · 任务 11 · 第 22 个计划 —— **构建脚本的 content 过滤
|
||||
</action>
|
||||
<behavior>
|
||||
- 根 `.jsonc` → 输出纯 JSON,后缀仍 `.jsonc`。
|
||||
- `defaults/*.jsonc` → 即使无清单引用也输出并压缩。
|
||||
- `defaults/*.jsonc` → 即使无清单引用、甚至 `defaults/` 内存在 `.list.jsonc`,也全量输出并压缩。
|
||||
- 有 `.list.jsonc` 的目录 → 清单命中(完整名或去扩展名主名)的文件保留,未命中文件不出现在输出。
|
||||
- `.list.jsonc` 自身 → 始终输出且已压缩。
|
||||
- 无 `.list.jsonc` 的非 `defaults` 子文件夹与根目录 → 全量输出(`.jsonc` 压缩、其它原样)。
|
||||
@ -325,8 +327,8 @@ Phase 9 · 任务 11 · 第 22 个计划 —— **构建脚本的 content 过滤
|
||||
<verify>
|
||||
<automated>cmd /c "pnpm exec vitest run script/build-resource.test.ts"</automated>
|
||||
<fails_when>non-zero exit,或任一断言失败(`defaults/` 被过滤 / 清单引用文件被剔除 / 未引用文件仍被输出 / `.list.jsonc` 被剔除或未压缩 / 根 `.jsonc` 未压成纯 JSON / `item.ts` 拷贝内容不一致 / 统计值与实际输出不一致)</fails_when>
|
||||
<automated>node -e "const fs=require('fs'),cp=require('child_process');const bad=[];const t=fs.readFileSync('script/build-resource.ts','utf8');for(const x of ['.list.jsonc','defaults','basename','JSON.parse','minifyJSONC','buildContent','Fontmin','chars: string','IContentBuildOptions','IContentBuildStats']){if(t.indexOf(x)<0)bad.push('build-resource.ts missing: '+x)}const commentMarks=['//','/*','*'];const isComment=l=>commentMarks.some(m=>l.startsWith(m));for(const f of ['script/build-resource.ts','script/build-plugin.ts']){let head='';try{head=cp.execSync('git show HEAD:'+f,{encoding:'utf8'})}catch(e){bad.push('cannot read HEAD version of '+f+': '+e.message)}const baseSet=new Set(head.split(/\r?\n/).map(l=>l.trim()).filter(isComment));const mins={'script/build-resource.ts':8,'script/build-plugin.ts':5};const min=mins[f] ? mins[f] : 1;if(baseSet.size<min)bad.push(f+' baseline comment lines too few ('+baseSet.size+'<'+min+'), comment gate would be vacuous');const curSet=new Set(fs.readFileSync(f,'utf8').split(/\r?\n/).map(l=>l.trim()));const lost=[...baseSet].filter(l=>!curSet.has(l));if(lost.length>0)bad.push(f+' lost '+lost.length+' existing comment/jsDoc line(s), first: '+lost[0])}if(!fs.existsSync('script/build-resource.test.ts'))bad.push('script/build-resource.test.ts missing');const sp='.planning/phases/09-minimum-browser-runnable/09-22-SUMMARY.md';if(!fs.existsSync(sp))bad.push('09-22-SUMMARY.md missing');else{const sm=fs.readFileSync(sp,'utf8');for(const tok of ['defaults','.list.jsonc','node_modules','build:game','D-96','shouldReplay']){if(sm.indexOf(tok)<0)bad.push('SUMMARY must record token: '+tok)}}if(bad.length>0){console.error('CONTENT FILTER GATE FAILED :: '+bad.join(' ; '));process.exit(1)}console.log('OK content filter: list retention + HEAD-baseline comments intact + SUMMARY tokens')"</automated>
|
||||
<fails_when>non-zero exit,或 stderr 含 "CONTENT FILTER GATE FAILED"(`build-resource.ts` 缺 `.list.jsonc` / `defaults` / `basename` / `JSON.parse` 等值标记 / 既有导出改成别名或丢失(`minifyJSONC` / `buildContent` / `IContentBuildOptions` / `IContentBuildStats`)/ `chars: string` 丢失 / **`git show HEAD:<file>` 基线中的既有注释或 jsDoc 行在 `build-resource.ts` 或 `build-plugin.ts` 中缺失(被删除或改写)** / 基线注释行数低于下限(门禁可能空洞)/ 缺测试文件 / 缺 SUMMARY 或 SUMMARY 未记录 `defaults`、`.list.jsonc`、`node_modules`、`build:game`、`D-96`、`shouldReplay`)</fails_when>
|
||||
<automated>node -e "const fs=require('fs'),cp=require('child_process');const bad=[];const t=fs.readFileSync('script/build-resource.ts','utf8');for(const x of ['.list.jsonc','defaults','basename','JSON.parse','minifyJSONC','buildContent','Fontmin','chars: string','IContentBuildOptions','IContentBuildStats']){if(t.indexOf(x)<0)bad.push('build-resource.ts missing: '+x)}const commentMarks=['//','/*','*'];const isComment=l=>commentMarks.some(m=>l.startsWith(m));for(const f of ['script/build-resource.ts']){let head='';try{head=cp.execSync('git show HEAD:'+f,{encoding:'utf8'})}catch(e){bad.push('cannot read HEAD version of '+f+': '+e.message)}const baseSet=new Set(head.split(/\r?\n/).map(l=>l.trim()).filter(isComment));const min=8;if(baseSet.size<min)bad.push(f+' baseline comment lines too few ('+baseSet.size+'<'+min+'), comment gate would be vacuous');const curSet=new Set(fs.readFileSync(f,'utf8').split(/\r?\n/).map(l=>l.trim()));const lost=[...baseSet].filter(l=>!curSet.has(l));if(lost.length>0)bad.push(f+' lost '+lost.length+' existing comment/jsDoc line(s), first: '+lost[0])}if(!fs.existsSync('script/build-resource.test.ts'))bad.push('script/build-resource.test.ts missing');const sp='.planning/phases/09-minimum-browser-runnable/09-22-SUMMARY.md';if(!fs.existsSync(sp))bad.push('09-22-SUMMARY.md missing');else{const sm=fs.readFileSync(sp,'utf8');for(const tok of ['defaults','.list.jsonc','node_modules','build:game','D-96','shouldReplay']){if(sm.indexOf(tok)<0)bad.push('SUMMARY must record token: '+tok)}}if(bad.length>0){console.error('CONTENT FILTER GATE FAILED :: '+bad.join(' ; '));process.exit(1)}console.log('OK content filter: list retention + build-resource.ts HEAD-baseline comments intact + SUMMARY tokens')"</automated>
|
||||
<fails_when>non-zero exit,或 stderr 含 "CONTENT FILTER GATE FAILED"(`build-resource.ts` 缺 `.list.jsonc` / `defaults` / `basename` / `JSON.parse` 等值标记 / 既有导出改成别名或丢失(`minifyJSONC` / `buildContent` / `IContentBuildOptions` / `IContentBuildStats`)/ `chars: string` 丢失 / **`git show HEAD:script/build-resource.ts` 基线中的既有注释或 jsDoc 行在当前 `build-resource.ts` 中缺失(被删除或改写)**(`build-plugin.ts` 的同口径门禁落在 Task 1 提交前,不在此处重复) / 基线注释行数低于下限(门禁可能空洞)/ 缺测试文件 / 缺 SUMMARY 或 SUMMARY 未记录 `defaults`、`.list.jsonc`、`node_modules`、`build:game`、`D-96`、`shouldReplay`)</fails_when>
|
||||
<automated>node -e "const fs=require('fs'),path=require('path');const bad=[];function names(f){const t=fs.readFileSync(f,'utf8').split(/\r?\n/).filter(l=>!l.trim().startsWith('//')).join('\n');const set=new Set();(function walk(v){if(typeof v==='string')set.add(v);else if(Array.isArray(v))v.forEach(walk);else if(v&&typeof v==='object')Object.values(v).forEach(walk)})(JSON.parse(t));return set}for(const d of ['animation','audio','font','maps','texture']){const dir=path.join('src','content',d);const list=path.join(dir,'.list.jsonc');if(!fs.existsSync(list)){bad.push('missing '+list);continue}const set=names(list);for(const e of fs.readdirSync(dir,{withFileTypes:true})){if(e.isDirectory()||e.name==='.list.jsonc')continue;const stem=e.name.slice(0,e.name.length-path.extname(e.name).length);if(!set.has(e.name)&&!set.has(stem))bad.push('unlisted asset would be dropped: '+path.join(dir,e.name))}}if(bad.length>0){console.error('CONTENT COVERAGE GATE FAILED :: '+bad.join(' ; '));process.exit(1)}console.log('OK content coverage: every existing asset under the 5 list folders is referenced by its list')"</automated>
|
||||
<fails_when>non-zero exit,或 stderr 含 "CONTENT COVERAGE GATE FAILED":某个素材子文件夹缺 `.list.jsonc`,或该目录内存在既未被完整文件名、也未被去扩展名主文件名命中的现存素材(真实施加过滤后会丢文件)</fails_when>
|
||||
<automated>cmd /c "pnpm exec eslint script/build-plugin.ts script/build-resource.ts script/build-game.ts script/build-plugin.test.ts script/build-resource.test.ts"</automated>
|
||||
@ -336,14 +338,14 @@ Phase 9 · 任务 11 · 第 22 个计划 —— **构建脚本的 content 过滤
|
||||
- `script/build-resource.ts` 按用户裁定 1 实现:根目录照常(且 `isRoot` 显式跳过过滤)、`defaults/` 全量、有清单的子文件夹只保留被引用文件、`.list.jsonc` 自身始终压缩输出、无清单目录全量
|
||||
- 清单解析走 `minifyJSONC`(去注释)+ `JSON.parse` + 递归收集字符串;匹配仅「完整文件名」与「去扩展名主文件名」两种精确方式;`minifyJSONC` 行为未改(只剥离整行 `//` 注释)
|
||||
- 既有导出名称与签名(`minifyJSONC` / `buildContent` / `IContentBuildOptions`(`chars: string`)/ `IContentBuildStats` / `IContentBuildCounter`)未改;字体分支与告警文案未改
|
||||
- `script/build-resource.test.ts` 覆盖 9 类用例(根 jsonc、**根目录存在 `.list.jsonc` 仍全量**、`defaults` 全量、maps 清单(fixture 清单原文含 `//` 注释且输出已剥离)、texture 对象清单、font 清单、无清单子文件夹全量、`item.ts` 原样、统计),每个 `it` 前一行注释
|
||||
- `processDirectory` / `minifyJSONC` / `compressFont` / `buildContent` 与接口成员的既有 jsDoc、以及 `script/build-plugin.ts` 的既有注释 **逐字未改**(由 `git show HEAD:<file>` 基线门禁证明;不依赖 git 暂存状态),过滤与删除的说明只写在新函数 / 新常量上
|
||||
- `script/build-resource.test.ts` 覆盖 9 类用例(根 jsonc、**根目录存在 `.list.jsonc` 仍全量**、`defaults` 全量(**`defaults/` 内存在 `.list.jsonc` 时仍全量**)、maps 清单(fixture 清单原文含 `//` 注释且输出已剥离)、texture 对象清单、font 清单、无清单子文件夹全量、`item.ts` 原样、统计),每个 `it` 前一行注释
|
||||
- `processDirectory` / `minifyJSONC` / `compressFont` / `buildContent` 与接口成员的既有 jsDoc **逐字未改**(由本任务的 `git show HEAD:script/build-resource.ts` 基线门禁证明,不依赖 git 暂存状态);`script/build-plugin.ts` 的既有注释由 **Task 1 提交前**的同口径门禁证明(基线已含新导出即自失败);过滤与删除的说明只写在新函数 / 新常量上
|
||||
- 五个改动文件通过范围内的 `eslint`(`pnpm exec eslint` 零报告)
|
||||
- 真实 `src/content` 清单覆盖率门禁通过(现有素材无一被过滤掉)
|
||||
- `09-22-SUMMARY.md` 已写并含 6 个必需关键字与三项已知边界
|
||||
- 未改 `packages-user/**` / `packages/**` / `src/**` / `package.json` / `index.html` / `dev.md` / `vite.config.ts` / lockfile / `script/dev.ts` / `script/build-lib.ts`
|
||||
</acceptance_criteria>
|
||||
<done>content 构建按清单过滤:`defaults/` 与无清单目录全量输出、根目录 `isRoot` 跳过过滤(即使出现 `.list.jsonc` 也不过滤)、5 个素材子文件夹只保留被引用文件、`.list.jsonc` 自身压缩输出、jsonc 仍压成纯 JSON;行为测试、HEAD 基线注释零丢失与真实清单覆盖率门禁全绿;范围内的 `eslint` 零报告;SUMMARY 记录两处修复与三项已知边界</done>
|
||||
<done>content 构建按清单过滤:`defaults/` 与无清单目录全量输出、根目录 `isRoot` 跳过过滤(即使出现 `.list.jsonc` 也不过滤)、5 个素材子文件夹只保留被引用文件、`.list.jsonc` 自身压缩输出、jsonc 仍压成纯 JSON;行为测试、`build-resource.ts` 的 HEAD 基线注释零丢失与真实清单覆盖率门禁全绿;范围内的 `eslint` 零报告;SUMMARY 记录两处修复与三项已知边界</done>
|
||||
</task>
|
||||
|
||||
</tasks>
|
||||
@ -377,8 +379,8 @@ Phase 9 · 任务 11 · 第 22 个计划 —— **构建脚本的 content 过滤
|
||||
|
||||
<verification>
|
||||
- **Task 0:** 预执行状态(09-21 构建脚本为当前实现 / 23 个 jsonc / 5 个清单目录 / `defaults` 8 个 jsonc / 修饰器定义存在 / `script/build-resource.test.ts` 不存在)检查;人工关卡(用户回复「可以执行」;OI-1 / OI-2 / OI-3 若被改名须先修订计划再获批);汇报须含三项已知边界与「既有 jsDoc 逐字保留」的说明。
|
||||
- **Task 1:** `script/build-plugin.ts` 结构(**按导出形态断言**:两个新导出 + `dataIsolationPlugin` 保留 / AST 定位标记 / `enforce: 'pre'` / `apply: 'build'` / `node_modules` 跳过,不硬编码提议命名);`build-game` **按函数切片**断言(从 `./build-plugin` 的导入绑定推导新插件名——`dataIsolationPlugin` + 恰好 1 个新绑定,`buildClient` 与 `buildData` 各含该绑定、`buildData` 仍含隔离插件、隔离插件不进 `buildClient`、定义顺序未变);`script/build-plugin.test.ts` 行为(删两类装饰器、参数含引号括号、字符串与注释不误删、`node_modules` 跳过、**对照式双装饰器** `vite.build()`:fixture 导出类 + 两个方法分别带 `@shouldReplay` / `@ignoreReplay` 且各返回 `mota_replay_probe` / `mota_ignore_probe` + 两个工厂本地不导出;`plugins: []` 对照产物含 `shouldReplay`、`ignoreReplay`、两个唯一字面量与两个方法名,带插件产物不含 `shouldReplay` / `ignoreReplay` 但两个唯一字面量与两个方法名仍在;结构门禁另行校验正/负向断言都在、工厂未被导出)。
|
||||
- **Task 2:** `script/build-resource.ts` 结构(`.list.jsonc` / `defaults` / `basename` / `JSON.parse` 值标记、既有导出与 `chars: string` 未变、**`git show HEAD:<file>` 基线注释行零丢失**,覆盖 `build-resource.ts` 与 `build-plugin.ts`,并校验基线行数下限防止门禁空洞);`script/build-resource.test.ts` 行为(根 jsonc、**根目录存在 `.list.jsonc` 仍全量**、`defaults` 全量、maps 清单保留与剔除 + 清单输出已剥离 `//`、texture 对象清单、font 清单、无清单子文件夹全量、`item.ts` 原样、统计);真实 `src/content` **清单覆盖率**(5 个清单目录内现存素材必须全部被命中);`eslint`(五个改动文件零报告);SUMMARY 关键字。
|
||||
- **Task 1:** `script/build-plugin.ts` 结构(**按导出形态断言**:两个新导出 + `dataIsolationPlugin` 保留 / AST 定位标记 / `enforce: 'pre'` / `apply: 'build'` / `node_modules` 跳过,不硬编码提议命名);`build-game` **按函数切片**断言(从 `./build-plugin` 的导入绑定推导新插件名——`dataIsolationPlugin` + 恰好 1 个新绑定,`buildClient` 与 `buildData` 各含该绑定、`buildData` 仍含隔离插件、隔离插件不进 `buildClient`、定义顺序未变);`script/build-plugin.test.ts` 行为(删两类装饰器、参数含引号括号、字符串与注释不误删、`node_modules` 跳过、**对照式双装饰器** `vite.build()`:fixture 导出类 + 两个方法分别带 `@shouldReplay` / `@ignoreReplay` 且各返回 `mota_replay_probe` / `mota_ignore_probe` + 两个工厂本地不导出;`plugins: []` 对照产物含 `shouldReplay`、`ignoreReplay`、两个唯一字面量与两个方法名,带插件产物不含 `shouldReplay` / `ignoreReplay` 但两个唯一字面量与两个方法名仍在;结构门禁另行校验正/负向断言都在、工厂未被导出);另加 `script/build-plugin.ts` 的「既有注释零丢失」门禁——**必须在 Task 1 的提交前执行**(`git show HEAD:script/build-plugin.ts` 基线,基线已含 `replayDecoratorPlugin` 即自失败)。
|
||||
- **Task 2:** `script/build-resource.ts` 结构(`.list.jsonc` / `defaults` / `basename` / `JSON.parse` 值标记、既有导出与 `chars: string` 未变、**`git show HEAD:script/build-resource.ts` 基线注释行零丢失**,并校验基线行数下限防止门禁空洞;`build-plugin.ts` 的同口径门禁在 Task 1 提交前执行);`script/build-resource.test.ts` 行为(根 jsonc、**根目录存在 `.list.jsonc` 仍全量**、`defaults` 全量(含 `defaults/.list.jsonc` 时仍全量)、maps 清单保留与剔除 + 清单输出已剥离 `//`、texture 对象清单、font 清单、无清单子文件夹全量、`item.ts` 原样、统计);真实 `src/content` **清单覆盖率**(5 个清单目录内现存素材必须全部被命中);`eslint`(五个改动文件零报告);SUMMARY 关键字。
|
||||
- **一致性:** `dist/content/**` 落点与 `src/data/constant.ts` 的 `content/core.jsonc` 一致;`build-game.ts` 的插件导入路径 `./build-plugin` 与 Task 1 产物一致;`script/build-resource.ts` 被 `build-game.ts` 以 `buildContent` / `IContentBuildOptions` 原名调用。
|
||||
- **无全仓门禁:** 不使用 `pnpm check:type` / `pnpm build` / 全量 `pnpm test:ci`(用户 WIP 存在历史类型错误);本计划**不端到端运行全量** `build:game`。
|
||||
- **人工复核:** 结论(含三项已知边界)写入 `09-22-SUMMARY.md`。
|
||||
@ -390,7 +392,7 @@ Phase 9 · 任务 11 · 第 22 个计划 —— **构建脚本的 content 过滤
|
||||
- **用户裁定 3 / 4(边界):** 只改构建脚本与其测试;未改 `build-lib.ts` / `package.json` / `index.html` / `dev.md` / `src/**` / `public/**` / `packages-user/**` / `packages/**` / `vite.config.ts` / lockfile / `script/dev.ts`;未改构建顺序;无特殊失败处理。
|
||||
- **D-93 / D-96 / D-98:** 任务 11 的构建脚本继续承担 content 处理;`build-game` 仍是唯一编排入口;未回退 09-21 已落地的数据端 ESM 产物与隔离检测。
|
||||
- **验证:** 两个测试文件与六个门禁(插件结构、content 结构 + `git show HEAD` 基线注释零丢失、真实清单覆盖率、`eslint`、SUMMARY 关键字,以及对照式**双装饰器** `vite.build()` 的正/负向双向断言)全部跑到确定结论;**未端到端运行全量 `build:game` 的事实已写入 SUMMARY**。
|
||||
- **注释纪律:** 既有 jsDoc / 注释逐字保留;新增说明只出现在新函数与新常量上(`build-resource.ts` 与 `build-plugin.ts` 均由 HEAD 基线门禁证明)。
|
||||
- **注释纪律:** 既有 jsDoc / 注释逐字保留;新增说明只出现在新函数与新常量上(`build-plugin.ts` 由 Task 1 提交前的 HEAD 基线门禁证明、`build-resource.ts` 由 Task 2 的 HEAD 基线门禁证明)。
|
||||
- **已知边界:** 生产产物不再产生录像安全检查信息(预期);`index.html` 仍引用 `/styles.css`(09-21 已记录);`animation` / `audio` / `font` 当前无素材,其过滤规则由测试覆盖。
|
||||
</success_criteria>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user