mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-04 10:41:01 +08:00
* feat(design-system): DS-3 最小语义 Token 影子层
在 packages/design-tokens 建立 reference → semantic 两层 DTCG 影子字典。
数据源仅为 DS-2b 冻结快照,零运行时接线;产品代码不改。
Signed-off-by: kirozeng <kirozeng@gmail.com>
* fix-run ds3-r1b wave1 squash
group g1 tip 793c462b68839fc857844d55b4e9d37031153c6b
Signed-off-by: kirozeng <kirozeng@gmail.com>
* fix(design-tokens): HSL 色值改用标准 DTCG 颜色对象,修复 Windows CRLF 假红
review 指出 12 个 HSL triplet reference 节点是自造的 $type: "other"——
它不是标准 DTCG token 类型,且校验器此前显式放行,测试全绿也发现不了。
对治理合同锁定的 Terrazzo 2.7.1 实测:other 类型 token 被 CSS 插件静默
丢弃(不产出任何 CSS 变量),alias 到它同样无输出;裸 triplet 字符串在
$type: color 下被解析成黑色。DS-8 接线时影子层无法直接承担生成切换。
- dtcg.ts 新增 toDtcgColorObject / dtcgColorObjectToString:HSL triplet →
{colorSpace:"hsl",components:[h,s,l]};hex/rgba/transparent → srgb 分量
(0-1) + 可选 alpha。$type 收紧为仅 color。
- build-layers.ts 删除 dtcgTypeFor 启发式,reference/semantic 全部节点
生成标准颜色对象;重生成两层 JSON(12 个 other reference + 14 个
other semantic alias 全部消除)。
- guards.ts:$type 校验不再放行 other;reference 只许颜色对象字面量,
semantic 只许 alias;逐值一致守卫改在颜色对象层比较(hex 大小写不构成
色值差异)。
- .gitattributes 给 packages/design-tokens/src/**/*.json 钉 eol=lf(drizzle
migration .sql 同款先例):Windows autocrlf 检出把生成物转 CRLF 导致
「磁盘 = 内存生成」字节一致守卫假红(本轮 CI Windows unit tests 红),
并补 git check-attr 回归测试钉住该契约。
- value-consistency.test.ts 补往返还原与 other 拒收的回归测试。
验证:pnpm --filter @cindy/design-tokens typecheck / vitest 19 测试全绿;
pnpm test:unit:related 全量绿;生成器两次运行字节一致;最终生成物过
Terrazzo 2.7.1 tz build 零 lint 错误,136 token 全部产出 CSS 变量。
Signed-off-by: Kirozeng <kirozeng@gmail.com>
* fix(design-tokens): 零接线守卫按文件位置解析相对 import,校验器检查分量范围
Codex 新一轮 review 两条 P1 的跟进:
① 相对路径接线漏检(成立):兄弟 workspace(packages/foo/src/a.ts)写
`../../design-tokens/src/…` 时说明符不含 packages/ 段,旧正则
`packages\/design-tokens\/(?:src|dist|build)\//` 漏检,零运行时接线守卫
会放行真实消费者。修法:新增 relativeSpecifierHitsDesignTokens——提取
from/import()/require()/import.meta.resolve() 语境下的相对说明符,按被
扫描文件的 repo 相对位置 resolve,落进 packages/design-tokens/ 即命中;
任意 ../ 深度、兄弟包与 apps 侧路径全覆盖。findRuntimeImportsOfDesignTokens
双通道检测,并补正反两组自证伪用例(全仓扫描零误报保持)。
② HSL 百分比分量应为 0–1(不成立):DTCG Color 模块 Color Space 表原文
是 hsl hue [0,360) / saturation / lightness [0,100]——s/l 用 0–100 不是
0–1,规范自己的白色示例就是 components: ["none", 0, 100]。Terrazzo 2.7.1
实测:[60, 12.5, 97] 产出 hsl(60 12.5% 97%)(正确),0–1 写法产出
hsl(60 0.125% 0.97%)(几乎全黑)。生成物不改。采纳意见的合理内核:
校验器现在按色彩空间检查分量合法范围(srgb 通道 [0,1]、hsl hue [0,360)
360 非法、s/l [0,100]、alpha [0,1]),把正确范围锁进守卫防止反向犯错,
并补越界反证用例。
验证:pnpm --filter @cindy/design-tokens typecheck 通过;22 个单测全绿
(新增 3 个);生成物未变(本轮零改动 rebase 在 77db609e2 之上)。
Signed-off-by: Kirozeng <kirozeng@gmail.com>
* fix(design-tokens): 相对说明符提取补副作用 import 语境
Codex review P2(3913379862)跟进:兄弟 workspace 写
`import '../../design-tokens/src/generate.ts'`(副作用导入,无 from 子句
无括号)时,SPECIFIER_CONTEXT_RE 四种语境都命不中,相对路径解析通道
漏检,零接线守卫会放行。
- 补 `import '…'` 分支:用 `(?=['"])` 前瞻定位引号(分支自身不吞引号,
引号由共享后继统一消费,`\s*` 覆盖换行形态),实测单行 / 换行 / 双引号
形态全部命中。
- 顺带修既有误报:import() / require() 分支此前无 `(?<![\w$.])` 守卫,
`foo.import('…')` / `foo.require('…')` 成员调用会被当 import 语句命中
(上一轮就存在,本轮一起收口);副作用 import 分支同款守卫。
- 反证用例:副作用 import 两种形态命中;foo.import / foo.require 成员
调用不误报;全仓扫描仍零命中。
验证:pnpm --filter @cindy/design-tokens typecheck 通过;22 单测全绿
(zero-wiring 新增 4 个断言形态)。
Signed-off-by: Kirozeng <kirozeng@gmail.com>
* fix(design-tokens): 零接线守卫剥离注释与字符串里的伪导入
Codex review P1(3913459489)跟进:守卫把源码全文直接喂正则,注释或错误
消息里出现完整 import 语句(如 `// import '@cindy/design-tokens';`)会被
当真实接线,required unit workspace 假红,无运行时接线的改动被 CI 阻断。
实测确认属实(此前『非导入语境不误报』用例能过只是因为缺完整 import
语法)。
- 新增 stripCommentsAndDataStrings:轻量状态机剥除行注释 / 块注释(替换
为等长空白,行列结构不变);字符串字面量按语境二分——开引号前以
from/import(/require(/import.meta.resolve(/import 语境结尾的是模块
说明符,保留原文;否则是数据字符串,内容替换为空白(引号保留)。
语境判定只看输出末尾 64 字符,避免全文件正则回溯。
- containsRuntimeImportOfDesignTokens / relativeSpecifierHitsDesignTokens
改两段式:先跑廉价正则,零命中(绝大多数文件)不付剥除成本;命中后
剥除复核,命中若来自注释/文案则判非真实接线。全仓扫描 3.8s,超时余量
提到 60s(Windows 慢盘)。
- 正则字面量不识别:只在『漏放』方向偏差(正则内容被清空不命中),真实
import 语句不会写在正则里,可接受——如实注释声明。
- 反证用例:注释(单行/块/JSDoc)/ 数据字符串 / 报错文案里的完整 import
语句全部不误报(两个通道都验);剥除后真实 import 全形态(含前面有
注释或数据字符串的)仍然命中;stripper 语义四组直接断言。
验证:pnpm --filter @cindy/design-tokens typecheck 通过;25 单测全绿
(zero-wiring 新增 3 个用例 17 个断言形态);全仓扫描仍零命中。
Signed-off-by: Kirozeng <kirozeng@gmail.com>
* fix(design-tokens): 零接线守卫剥除顺序前置,修复注释隔断的合法导入漏检
Codex review P2(3913603623)跟进:`import(/* webpackChunkName: "tokens" */
'../../design-tokens/src/snapshot.ts')` 这类说明符前带合法注释的导入,两个
检测通道都漏检。根因是上一轮两段式的顺序缺陷:廉价正则预扫跑在原始文本
上,注释隔断了关键字→引号衔接,预扫零命中提前返回,剥除层(本可剥掉注释
恢复衔接)反而执行不到——防误报的层顺序自己制造了漏放。
- 剥除前置:containsRuntimeImportOfDesignTokens 与
relativeSpecifierHitsDesignTokens 都改为先剥注释/数据字符串、再跑正则。
注释的两个方向(伪命中 / 遮蔽真命中)都由剥除层统一解决。
- 性能:stripCommentsAndDataStrings 重写为 chunked 状态机——普通文本按
区间整段拷贝(不再逐字符拼接),语境判定从后往前拼接 chunk 凑 64 字符
窗口;7.7MB 真实包源码 59ms(125MB/s,较逐字符版 5.9MB/s 提速 21 倍)。
另加 import/require/from 关键字 includes 预检,无语法痕迹的文件零成本。
全仓扫描 1.24s(较上轮 3.8s 基线更快)。
- 反证用例:动态 import / require / 副作用 import 带注释的相对路径走
rel 通道、包 id 带注释走 id 通道,各自命中;注释/数据字符串误报形态
回归保持全绿。
验证:pnpm --filter @cindy/design-tokens typecheck 通过;26 单测全绿;
全仓扫描仍零命中零误报。
Signed-off-by: Kirozeng <kirozeng@gmail.com>
* fix(design-tokens): 导入语境判定去长度窗口,member-require 不再被后顾排除
Codex review 两条 P1 跟进:
① 固定 64 字符窗口判语境(3913687085,成立):>64 字符的块注释剥成
空白后把 import( 挤出 tail 窗口,说明符被当数据字符串清空,两通道漏放。
修法采纳「状态机直接保留导入语境」:维护 lastCodeContext(无空白压缩的
最近输出,注释与空白不推进),判定时 trimEnd 后匹配——任意长度注释
都不再影响语境,无长度上限。实测 100/300 字符注释形态全命中。
② module.require 被负向后顾排除(3913687096,成立):`module.require()`
是 Node 真实模块加载 API,`(?<![\\w$.])` 却因 . 前缀拒绝匹配。修法:
后顾放宽为 `(?<![\\w$])`(只排除 myImport 标识符连写),. 前缀放行;
foo.import( 这类自定义成员调用同被命中——宁误报不漏放,守卫拦截的是
「有人真接线」,member-require 恰是合法接线形态。IMPORT_ENTRY_PATTERNS
与 SPECIFIER_CONTEXT_RE 两处同步。
行为变更如实声明:foo.import('…') / foo.require('…') 从「不误报白名单」
移入「命中集」——上一轮把它们列为不误报用例,本轮按威胁模型反转并在
测试里注明理由;标识符连写(myImport)仍排除。
验证:pnpm --filter @cindy/design-tokens typecheck 通过;28 单测全绿
(新增 2 个 P1 用例);全仓扫描 1.9s 零命中零误报。
Signed-off-by: Kirozeng <kirozeng@gmail.com>
* fix(design-tokens): 零接线扫描纳入 require.resolve 加载入口
Codex review P2(3913799524)跟进:产品包通过
`readFileSync(require.resolve('../../design-tokens/src/semantic/color.json'), 'utf8')`
消费影子层时是真实运行时消费者,但剥离层把 require.resolve 的参数当普通
数据字符串清空,包 id 与相对路径两个通道都返回 false——漏放。实测确认
(含 module.require.resolve 成员链)。
- SPECIFIER_CONTEXT_RE / SPECIFIER_PREFIX_RE 补 require.resolve 语境
(`require\s*\.\s*resolve\s*\(` 容忍空格形态);IMPORT_ENTRY_PATTERNS
补 require.resolve( 模块 id 形态。
- 反证用例:readFileSync(require.resolve(…))(包 id / 相对路径)、裸
require.resolve、module.require.resolve 成员链全部命中;注释/数据字符串/
myResolve 标识符回归不误报。
验证:pnpm --filter @cindy/design-tokens typecheck 通过;29 单测全绿;
全仓扫描 1.9s 零命中零误报。
Signed-off-by: Kirozeng <kirozeng@gmail.com>
* fix(design-tokens): 零接线扫描纳入模板字面量形式的模块说明符
Codex review P1(3913883249)跟进:`import(`../../design-tokens/src/snapshot.ts`)`、
`require(`@cindy/design-tokens/src/snapshot.ts`)` 这类无插值模板字面量是
有效运行时加载,但提取正则只认单双引号——包 id 与相对路径两个通道都漏放。
实测确认。
- SPECIFIER_CONTEXT_RE / IMPORT_ENTRY_PATTERNS 的引号字符类从 ['"] 扩到
['"`],全部六种语境(from / import() / require() / require.resolve /
import.meta.resolve / 裸副作用 import)同步。
- 带 ${…} 插值的模板**同样命中**:路径在运行期拼装恰是零接线阶段不该
出现的动态消费形态,按宁误报不漏放处理(与 member-require 同一威胁
模型,如实声明)。
- 数据语境的普通模板不误报:剥离层在非说明符位置把模板内容剥成空白,
既有机制无需改动。
- 反证用例:import/require/require.resolve/from/副作用 import 的模板形态
(包 id + 相对路径 + 插值)全部命中;数据模板回归不误报。
验证:pnpm --filter @cindy/design-tokens typecheck 通过;30 单测全绿;
全仓扫描 2.4s 零命中零误报。
Signed-off-by: Kirozeng <kirozeng@gmail.com>
* fix(design-tokens): 语义豁免色登记 exemption 元数据,fs 裸相对路径直读纳入零接线扫描
Codex review 两条 P2 跟进:
① 豁免色缺 protected 登记(3914411235,成立):destructive / error-* /
warning-* / focus-ring* 已进 semantic 建模,但 DESIGN.md §10 列其为
theme-invariant 语义豁免色、治理合同 §3.2 要求 Tier-3 豁免色作为 protected
角色迁移——分类里却是无元数据的普通 literal,DS-8 生成主题入口时无法区分
可覆写 semantic 与必须保留原值的豁免族。修法:新增 SEMANTIC_EXEMPTION_IDS
与 exemption 元数据(与 PROTECTED_IDS 并列、语义不同——豁免色**照常建模**
只带标记,protected 是「只登记不建模」);ClassificationEntry 加 exemption
字段,11 个已建模豁免色重新生成登记;新守卫 assertSemanticExemptionsRegistered
校验已建模豁免色必须带标记且不与 protected 混用。
② fs 裸相对路径直读漏检(3914411249,成立):
readFileSync('../../design-tokens/src/semantic/color.json') 是最直接的
消费方式,两通道都漏。修法:fs API 路径参数成为第八类说明符语境
(readFileSync/readFile/writeFileSync/existsSync/statSync 等 13 个 API 的
第一参数,含成员链与模板形态),按调用文件位置 resolve。误报核查:第一方
代码既有 fs 读取全部走 resolve(__dirname…) / new URL(…) 包装(54 处实测),
裸相对形态为零——纳入扫描零误报,全仓扫描实证。
验证:pnpm --filter @cindy/design-tokens typecheck 通过;33 单测全绿
(新增豁免色守卫 + fs 检测两组用例);全仓扫描 3.0s 零命中零误报;
生成器两次运行字节一致。
Signed-off-by: Kirozeng <kirozeng@gmail.com>
* fix(design-tokens): 零接线扫描纳入路径构造器与 Windows 反斜杠说明符
Codex review 两条 P2 跟进:
① 路径构造器包装漏检(3914597287,成立):
`readFileSync(resolve(__dirname, '../../design-tokens/…'))` / `join(…)`
是仓内既有 fs 读取的主流写法(54 处实测),旧实现只认 fs API 第一参数
直接以引号开始——包装形态两通道都漏。修法:resolve/join 调用内的静态
字符串片段(任意参数位置)成为第九类说明符语境,按调用文件位置 resolve
(__dirname ≈ 文件所在目录)。剥离层语境判定同步(resolve(/join( 开括号
后未闭括号内的字符串保留)。误报核查:既有 54 处用法全部不指向
design-tokens,Array.join 分隔符字符串不以 '.' 开头天然过滤——全仓扫描
零误报实证。
② Windows 反斜杠说明符漏检(3914597300,成立):
`require('..\\..\\design-tokens\\src\\x')` 在 Windows CJS 合法,
但说明符直接交给 path.posix、反斜杠不被识别为分隔符——resolve 结果不
落进 design-tokens,漏放。修法:说明符统一反斜杠归一为 / 再 resolve
(源码字符串里 \\ 是转义单反斜杠;仓内无含反斜杠字符的 POSIX 文件名,
替换是安全近似)。
验证:pnpm --filter @cindy/design-tokens typecheck 通过;35 单测全绿
(新增两组 11 个断言形态);全仓扫描 3.1s 零命中零误报。
Signed-off-by: Kirozeng <kirozeng@gmail.com>
* fix(design-tokens): 路径构造器重建全部静态参数,Tier-1 受保护 slot 照常语义建模
Codex review 两条 P2 跟进:
① 路径构造器只捕获第一个字符串参数(3914703193,成立):
`join(__dirname, '..', '..', 'design-tokens/…')` 分段拼接形态实际读取
design-tokens,但正则只看第一个 '..' 就返回 false——常见分段写法绕过
守卫。修法:重建调用内**全部**静态字符串参数——PATH_CONSTRUCTOR_CALL_RE
捕获完整调用实参区,按序提取字符串字面量拼成候选路径再按文件位置
resolve(非字符串参数天然缺席,等价于从文件目录起算的相对段)。反证:
分段 join / 多段 resolve / 模板段全命中;既有 54 处用法与 Array.join
分隔符回归零误报。
② 受保护 Tier-1 文本角色被移出 semantic(3914703199,成立):
text-secondary / text-secondary-cross 是 DESIGN.md §10 Tier-1 slot,
治理合同 §3.2 明确「Tier-1 semantic slots → semantic,名称与用途延续」;
却被 PROTECTED_IDS 统一 register-only 分支标成只登记、从 semantic JSON
消失——DS-8 接管生成时无法从新真相源生成这两个核心文本变量。U2 保护
限制的是改值须裁决(never darken unilaterally),不等于禁止迁移。
修法:ProtectedRule 加 mode 字段——Tier-1 slot(text-secondary /
text-secondary-cross)semantic-modeled:照常值形态分类 + 强制进
semantic + 保留 protected 元数据;Tier-3 singleton(annotation-accent、
login-brand-*)维持 register-only(治理合同「保留原位,逐项裁决,默认
不动」,本 PR 未裁决它们进 semantic)。守卫 assertProtectedNotSemantic
按 mode 分支校验;SEMANTIC_ROLES 补登记两个 Tier-1 slot。
验证:pnpm --filter @cindy/design-tokens typecheck 通过;35 单测全绿
(oracle 与保护值用例同步 mode 语义;value-consistency 验证
text-secondary 双模式值与冻结快照一致);全仓扫描零命中零误报;
生成器两次运行字节一致。
Signed-off-by: Kirozeng <kirozeng@gmail.com>
* fix(design-tokens): 零接线扫描纳入 import.meta.glob,语境判定锚定开引号
Codex review 两条 P2 跟进:
① import.meta.glob 漏检(3914869131,成立):Vite 的
`import.meta.glob('../../design-tokens/src/**/*.json')` 在构建期把影子层
内容打进产品(仓内 packages/lizi-mcps/src/browser/recipe-loader.ts 有
实际用例),但说明符语境没有 import.meta.glob 分支——两通道漏放。修法:
SPECIFIER_CONTEXT_RE / SPECIFIER_PREFIX_RE 补 import.meta.glob( 分支,
相对 glob 模式按文件位置 resolve(glob 元字符不影响前缀段判定)。
② 语境残留误报(3914869140,成立):`import x from './x'; const hint =
'packages/design-tokens/src/x';` 被误报——SPECIFIER_PREFIX_RE 的
\\bfrom / \\bimport 分支在 2320ce02 轮重写时丢失了 \\$ 锚定,匹配的是
「语境里任何位置有 import 字样」而非「语境以 import 结尾」,数据字符串被
剥除层错误保留、裸路径模式随后误报接线。修法:所有分支共享末尾 \\$ 锚定
((?:…)$ 整组包裹),保证匹配的是紧邻当前开引号的调用语境。
反证用例:glob(含模板形态与既有 recipes 用法不误报)、残留语境三种形态
不误报;此前全部九类语境 + 注释/数据字符串回归(23 形态)全绿。
验证:pnpm --filter @cindy/design-tokens typecheck 通过;37 单测全绿;
全仓扫描零命中零误报。
Signed-off-by: Kirozeng <kirozeng@gmail.com>
* fix(design-tokens): 零接线扫描纳入 fs/promises.open 与 .mts/.cts 源码
Codex review 两条 P2 跟进:
① fs/promises.open 漏检(3915016839,成立):
`const file = await open('../../design-tokens/src/semantic/color.json');
await file.readFile()` 真实消费影子层,但 open 不在 fs API 列表(openSync
在、异步 open 不在)——路径字符串被剥除,两通道漏放。修法:open 加入
FS_API_PATH_CONTEXT_RE 与 SPECIFIER_PREFIX_RE,预检补 open 字样(裸
open('…') 不含 File/Sync,此前连剥除层都进不去)。误报核查:window.open
的 URL 参数不以 '.' 开头天然过滤;仓内以 '.' 开头字符串参数的 open( 调用
实测为零。
② .mts/.cts 扫描缺口(3915016844,成立):扫描器扩展名正则只认
ts/tsx/js/mjs/cjs,.mts/.cts(有效 Node/TS 模块扩展,仓内 scripts/ 与
tools/ 已使用)的文件在读取内容前被跳过——相对路径消费且不留
package.json 依赖,两通道都看不见。修法:扩展名正则补 mts|cts,并用
临时 fixture(.mts 与 .cjs 消费者各一)直接验证扫描器行为。
验证:pnpm --filter @cindy/design-tokens typecheck 通过;38 单测全绿;
全仓扫描零命中零误报。
Signed-off-by: Kirozeng <kirozeng@gmail.com>
---------
Signed-off-by: kirozeng <kirozeng@gmail.com>
Signed-off-by: Kirozeng <kirozeng@gmail.com>
261 lines
13 KiB
JavaScript
261 lines
13 KiB
JavaScript
import os from 'node:os';
|
|
|
|
import { nodeWebstorageEnabled } from './shared/node-webstorage.mjs';
|
|
|
|
const vitestBin = (...args) => ({ type: 'packageBin', bin: 'vitest', args });
|
|
// The unit tier pins the threads pool. Vitest's default `forks` pool keeps
|
|
// `isolate` on and so recycles a child process per test file: this tier's ~1845
|
|
// files cost ~1.9k process spawns per gate run, measured at 21 LaunchServices
|
|
// check-ins/second on an 18-core macOS host. On 2026-07-30 that sustained churn
|
|
// took down macOS 27.0 beta's launchservicesd, which came back with an empty
|
|
// running-application registry — leaving the session with no frontmost app at
|
|
// all: no menu bar, no keyboard input anywhere, Dock tiles vanishing on click,
|
|
// and only a reboot to recover. Worker threads keep the same per-file isolation
|
|
// at zero process cost (same 180 desktop files: 189 check-ins versus 1,
|
|
// identical results, slightly faster).
|
|
//
|
|
// Not everything moves. The heavy manual tiers (db, migration, git-integration)
|
|
// stay on the default pool: they bootstrap runtime assets and drive real
|
|
// Git/SQLite subprocesses, and none sits on the PR gate path. A workspace also
|
|
// opts out when its tests cannot survive a worker thread; the known blockers
|
|
// are recorded at their call site below — desktop needs the webstorage flag on a
|
|
// Node that installs those globals, and the flag cannot coexist with worker
|
|
// threads (scripts/shared/node-webstorage.mjs), while maker-core fakes HOME,
|
|
// which a worker cannot see because `process.env` there is a thread-local copy
|
|
// while `os.homedir()` reads the real environment through libuv.
|
|
//
|
|
// win32 opts desktop out wholesale: on Windows (Node 24.14.1, 2026-07-30) the
|
|
// desktop suite under threads segfaulted the whole vitest process (exit 139)
|
|
// on 2 of 2 runs — same native-addon-finalizer-in-isolate-teardown crash
|
|
// class node-webstorage.mjs documents, only without execArgv in play — while
|
|
// forks passed 15651 tests twice in a row. The churn this pool exists to
|
|
// avoid is a LaunchServices problem; Windows has no launchservicesd, so forks
|
|
// costs it nothing.
|
|
//
|
|
// Keep every opt-out listed in the pool regression test, and keep the list
|
|
// short: at 1330 of this tier's 1845 files, desktop alone decides whether the
|
|
// churn is a trickle or back to where it started.
|
|
const UNIT_POOL_DEFAULT = 'threads';
|
|
const UNIT_TEST_SHARD_ENV = 'XDT_UNIT_TEST_SHARD';
|
|
|
|
/**
|
|
* Split every Vitest workspace by the same CI shard so the two Windows jobs
|
|
* still form one complete unit gate. The runner adds `passWithNoTests` only
|
|
* when a workspace has fewer selected files than the configured shard count.
|
|
*/
|
|
export function unitTestShardArgs(value = process.env[UNIT_TEST_SHARD_ENV]) {
|
|
if (value == null || String(value).trim() === '') return [];
|
|
const normalized = String(value).trim();
|
|
const match = /^(\d+)\/(\d+)$/.exec(normalized);
|
|
if (!match) throw new Error(`${UNIT_TEST_SHARD_ENV} must use <index>/<count>`);
|
|
const index = Number(match[1]);
|
|
const count = Number(match[2]);
|
|
if (!Number.isSafeInteger(index) || !Number.isSafeInteger(count) || index < 1 || count < 1 || index > count) {
|
|
throw new Error(`${UNIT_TEST_SHARD_ENV} must satisfy 1 <= index <= count`);
|
|
}
|
|
return [`--shard=${index}/${count}`];
|
|
}
|
|
|
|
// Workspace-level parallelism owns the global process budget. Keep ordinary
|
|
// Vitest workspaces at one worker each so outer concurrency cannot multiply
|
|
// every child process's default CPU-sized pool.
|
|
const unitVitestCommand = (workers = 1, pool = UNIT_POOL_DEFAULT) =>
|
|
vitestBin('run', `--pool=${pool}`, `--maxWorkers=${workers}`, ...unitTestShardArgs());
|
|
const noCollectableTestsReason = 'No collectable tests yet. Add tests and mark a tier required when this workspace gains testable logic.';
|
|
const desktopDbInclude = [
|
|
'src/main/localDb/**/__tests__/*.test.ts',
|
|
'src/main/scheduler-host/__tests__/*.db.test.ts',
|
|
'src/main/__tests__/schemaDriftRepair.test.ts',
|
|
'src/main/__tests__/betterSqliteFactory.test.ts',
|
|
'src/main/__tests__/codexHistoryPromptInit.test.ts',
|
|
'src/main/__tests__/orcaStaleIndexCleanup.test.ts',
|
|
'src/main/__tests__/*LocalSessions.test.ts',
|
|
];
|
|
const desktopDbExclude = [
|
|
'src/main/localDb/__tests__/migrationReplay.test.ts',
|
|
'src/main/localDb/__tests__/drizzle-proxy-perf.test.ts',
|
|
];
|
|
const desktopGitIntegrationInclude = [
|
|
'src/main/**/*.git-integration.test.ts',
|
|
];
|
|
|
|
export function desktopUnitWorkerCount(
|
|
availableParallelism = os.availableParallelism(),
|
|
) {
|
|
const available = Number.isFinite(availableParallelism)
|
|
? Math.floor(availableParallelism)
|
|
: 1;
|
|
return Math.max(1, Math.min(8, available));
|
|
}
|
|
|
|
const noCollectableWorkspace = (name, cwd, reason = noCollectableTestsReason) => ({
|
|
name,
|
|
cwd,
|
|
status: 'notApplicable',
|
|
reason,
|
|
tiers: {},
|
|
});
|
|
|
|
const requiredUnitWorkspace = (name, cwd, { workers = 1, execution, pool } = {}) => ({
|
|
name,
|
|
cwd,
|
|
status: 'required',
|
|
tiers: {
|
|
unit: {
|
|
status: 'required',
|
|
...(execution ? { execution } : {}),
|
|
command: unitVitestCommand(workers, pool),
|
|
},
|
|
},
|
|
});
|
|
|
|
export default {
|
|
workspaces: [
|
|
{
|
|
name: 'desktop',
|
|
cwd: 'apps/desktop',
|
|
status: 'required',
|
|
tiers: {
|
|
unit: {
|
|
status: 'required',
|
|
execution: 'exclusive',
|
|
// Desktop unit tests spawn many Git/filesystem subprocesses. Benchmarking
|
|
// found eight workers to be the best complexity/resource tradeoff.
|
|
// Lower-CPU hosts stay capped by their available parallelism.
|
|
// It runs exclusively so these workers never overlap outer workspaces.
|
|
// The pool follows the webstorage flag, because the flag cannot
|
|
// coexist with worker threads — see scripts/shared/node-webstorage.mjs
|
|
// for the crash it causes and the measurements. On Node 22, which is
|
|
// what local dev and CI run, the flag is a no-op, so this suite's 1330
|
|
// files take threads and stop spawning a process each. On a
|
|
// webstorage-enabled Node the flag wins and the suite stays on forks.
|
|
// win32 stays on forks unconditionally — threads segfaults there and
|
|
// the churn threads exists to avoid is macOS-only (see the pool note
|
|
// at the top of this file).
|
|
command: unitVitestCommand(
|
|
desktopUnitWorkerCount(),
|
|
nodeWebstorageEnabled() || process.platform === 'win32'
|
|
? 'forks'
|
|
: 'threads',
|
|
),
|
|
exclude: [
|
|
'**/*.git-integration.test.ts',
|
|
'src/main/localDb/**',
|
|
'src/main/__tests__/*Migration.test.ts',
|
|
'src/main/__tests__/schemaDriftRepair.test.ts',
|
|
'src/main/__tests__/betterSqliteFactory.test.ts',
|
|
'src/main/__tests__/*LocalSessions.test.ts',
|
|
'src/main/__tests__/codexHistoryPromptInit.test.ts',
|
|
'src/main/__tests__/orcaStaleIndexCleanup.test.ts',
|
|
'src/main/scheduler-host/__tests__/*.db.test.ts',
|
|
'src/main/__tests__/directSessionSendGuard.test.ts',
|
|
'src/main/__tests__/makerSendToSessionOrdering.test.ts',
|
|
'**/*.bench.ts',
|
|
],
|
|
},
|
|
'git-integration': {
|
|
status: 'manual',
|
|
reason: 'Full real-Git coverage is explicit because it spawns hundreds of local subprocesses and is coordinated across worktrees.',
|
|
execution: 'exclusive',
|
|
coverage: 'allowlist',
|
|
command: vitestBin('run', `--maxWorkers=${desktopUnitWorkerCount()}`),
|
|
include: desktopGitIntegrationInclude,
|
|
},
|
|
db: {
|
|
status: 'manual',
|
|
reason: 'Desktop DB tests remain an explicit DB tier because they bootstrap runtime assets and cover localDb behavior outside fast unit.',
|
|
coverage: 'allowlist',
|
|
preflight: [
|
|
{ type: 'packageScript', script: 'ensure-deps' },
|
|
{ type: 'packageScript', script: 'ensure-dev-runtime-assets' },
|
|
],
|
|
command: vitestBin('run'),
|
|
include: desktopDbInclude,
|
|
exclude: desktopDbExclude,
|
|
},
|
|
migration: {
|
|
status: 'manual',
|
|
reason: 'Migration replay remains an explicit DB tier because it replays SQLite history fixtures outside fast unit.',
|
|
coverage: 'allowlist',
|
|
preflight: [
|
|
{ type: 'packageScript', script: 'ensure-deps' },
|
|
{ type: 'packageScript', script: 'ensure-dev-runtime-assets' },
|
|
],
|
|
command: vitestBin('run'),
|
|
include: [
|
|
'src/main/localDb/__tests__/migrationReplay.test.ts',
|
|
'src/main/__tests__/*Migration.test.ts',
|
|
],
|
|
},
|
|
'db-perf': {
|
|
status: 'manual',
|
|
reason: 'DB proxy performance is intentionally explicit because strict timing is host-sensitive.',
|
|
coverage: 'allowlist',
|
|
command: { type: 'packageScript', script: 'test:db-proxy-perf' },
|
|
include: ['src/main/localDb/__tests__/drizzle-proxy-perf.test.ts'],
|
|
},
|
|
guard: {
|
|
status: 'required',
|
|
coverage: 'allowlist',
|
|
command: vitestBin('run'),
|
|
include: [
|
|
'src/main/__tests__/directSessionSendGuard.test.ts',
|
|
'src/main/__tests__/makerSendToSessionOrdering.test.ts',
|
|
],
|
|
},
|
|
},
|
|
},
|
|
// Mobile has enough test files to become the critical path at one worker.
|
|
// Give it the full worker budget, but never overlap it with other workspaces.
|
|
requiredUnitWorkspace('mobile', 'apps/mobile', { workers: 4, execution: 'exclusive' }),
|
|
requiredUnitWorkspace('@cindy/anthropic-compat-proxy', 'packages/anthropic-compat-proxy'),
|
|
requiredUnitWorkspace('@cindy/anthropic-responses-bridge', 'packages/anthropic-responses-bridge'),
|
|
requiredUnitWorkspace('@cindy/responses-anthropic-bridge', 'packages/responses-anthropic-bridge'),
|
|
requiredUnitWorkspace('@cindy/responses-chat-bridge', 'packages/responses-chat-bridge'),
|
|
requiredUnitWorkspace('@cindy/auth-client', 'packages/auth-client'),
|
|
requiredUnitWorkspace('@cindy/browser-control-runtime', 'packages/browser-control-runtime'),
|
|
requiredUnitWorkspace('cindy-tools', 'packages/cindy-tools'),
|
|
requiredUnitWorkspace('@cindy/device-link', 'packages/device-link'),
|
|
noCollectableWorkspace('@cindy/embedding-client', 'packages/embedding-client'),
|
|
requiredUnitWorkspace('@cindy/file-browser-core', 'packages/file-browser-core'),
|
|
noCollectableWorkspace('@cindy/github-client', 'packages/github-client'),
|
|
noCollectableWorkspace('@cindy/gitlab-client', 'packages/gitlab-client'),
|
|
noCollectableWorkspace('@cindy/heartbeat-client', 'packages/heartbeat-client'),
|
|
requiredUnitWorkspace('@cindy/im', 'packages/lizi-im'),
|
|
requiredUnitWorkspace('@cindy/mcps', 'packages/lizi-mcps'),
|
|
requiredUnitWorkspace('@cindy/ios-simulator-runtime', 'packages/ios-simulator-runtime'),
|
|
requiredUnitWorkspace('@cindy/maker-cc-manager', 'packages/maker-cc-manager'),
|
|
// Stays on forks: palette-scanner's tests stub HOME and the scanner resolves
|
|
// it through os.homedir(), which a worker thread cannot see (see
|
|
// UNIT_POOL_DEFAULT above).
|
|
requiredUnitWorkspace('@cindy/maker-core', 'packages/maker-core', { pool: 'forks' }),
|
|
requiredUnitWorkspace('@cindy/maker-remote-ssh', 'packages/maker-remote-ssh'),
|
|
// 轮 42:新包 maker-pi-manager(TS 单例 pi daemon)已随 SSH remote 交付;
|
|
// 漏登记会让 test-workspaces 的 manifest 覆盖校验失败(全量门禁拒跑)。
|
|
requiredUnitWorkspace('@cindy/maker-pi-manager', 'packages/maker-pi-manager'),
|
|
requiredUnitWorkspace('@cindy/maker-scheduler', 'packages/maker-scheduler'),
|
|
requiredUnitWorkspace('@cindy/maker-shared', 'packages/maker-shared'),
|
|
requiredUnitWorkspace('@cindy/model-providers', 'packages/model-providers'),
|
|
{
|
|
name: '@cindy/orca-workflow',
|
|
cwd: 'packages/orca-workflow',
|
|
status: 'required',
|
|
tiers: {
|
|
unit: {
|
|
status: 'required',
|
|
command: unitVitestCommand(),
|
|
include: ['src/__tests__/**/*.test.ts'],
|
|
},
|
|
},
|
|
},
|
|
noCollectableWorkspace('project-context', 'packages/project-context'),
|
|
requiredUnitWorkspace('@cindy/remote-file-service', 'packages/remote-file-service'),
|
|
requiredUnitWorkspace('@cindy/voice-input-core', 'packages/voice-input-core'),
|
|
requiredUnitWorkspace('@cindy/wechat-ilink', 'packages/wechat-ilink'),
|
|
noCollectableWorkspace('@cindy/device-link-protocol', 'packages/device-link-protocol'),
|
|
requiredUnitWorkspace('@cindy/plugin-protocol', 'packages/plugin-protocol'),
|
|
requiredUnitWorkspace('@cindy/slack-hook-protocol', 'packages/slack-hook-protocol'),
|
|
requiredUnitWorkspace('@cindy/design-tokens', 'packages/design-tokens'),
|
|
],
|
|
};
|