测试用例编写指南
write-tests
在编写或修改 tests/ 或 unittests/ 目录下的任何内容,或工具自身的测试之前阅读——包括用例工作流、单元测试、硬性规则以及已知的陷阱。
- License 许可
- Apache-2.0
- 所属仓库
- clice-io/clice
- 最近更新
- 2026-11-15
- Stars
- ★ 1.4k
- Forks
- 89
01 前言 Front Matter
- name
- write-tests
- description
- Read before writing or modifying anything under tests/ or unittests/, or the tools' own tests — the case workflow, unit tests, hard rules and known pitfalls.
03 SKILL.md 正文
Writing clice tests
Every test but the C++ unit tests is a case: a directory
tests/<topic>/<subtopic>/NN_name/ that is a small project of its own,
with the test.ts that says what to check (its own or inherited from its
subtopic or topic), a README.md when it belongs in the docs, and
snap.toml, every output it pins. tests/README.md is the
contract: topics, inputs and markers, the two kinds of test (answers,
test), the clients, outputs and how they render, docs, waiting and
teardown. Read it before writing a case; this skill adds only the workflow,
the hard rules and the pitfalls. The framework is tools/testing/
(@clice/tools/testing). tests/ keeps the compat and Zed suites.
Workflow
- Place the case by product area, not by the way it checks: the topic and
subtopic of the behavior (
tools/testing/cases/topics.tslists the topics). Copy the shape of 2-3 neighboring cases; one project per case, shared by several tests. - Write the inputs, with
§markers where the tests ask; atest.tsonly when the inherited script does not fit; aREADME.mdonly when the case shows a capability a reader should see. A case that pins an edge or a fixed bug has no README. - Run it alone, on the box the build ran on (the test skill):
CLICE_CASES=<topic>/<subtopic>/NN_name pixi run -e test-run cases-test.UPDATE_SNAPSHOTS=1writes itssnap.tomland prints what changed: review every block like code. It is written on the box:box cp $id . <case dir>brings it back before the nextbox pushoverwrites it. Every run also writes a documented case's card underdocs/cards/, which git ignores: CI makes the cards the site draws. What clice gets wrong stays in the output, withwrong = "<reason>"on the block. - Gate:
pixi run npm run checkat the repo root (strict tsc + ESLint, zero tolerance). Page regions and translations are synced, anddocs-checkrun, once at the end of the branch (the docs skill's "Syncing docs at the end of a branch").
Hard rules
.fails,.todoand a weakened assertion or snapshot are skipping a test (CLAUDE.md).except: { <platform>: "why" }is for a test with no meaning on a platform, never for one that fails there.- An
answerstest whose inspect and server outputs differ shows a real divergence: fix it, or declarepathswith the reason. NeverUPDATE_SNAPSHOTSover it. - URIs in server replies are validated strictly
(
tools/testing/render/paths.ts). Do not "normalize away" a malformed URI; a raw path or unencoded space is a server bug. - Comments:
///for doc comments,//inline; explain constraints the code can't show, nothing else. A documented case's sources are what its card shows: its maintainer notes go in itstest.ts. An undocumented case keeps them in its sources, never in atest.tsthat only copies the inherited script to hold them. - Every test runs on a fresh copy of its case. Probes and experiments work
on a copy too (
CLICE_KEEP_WORKSPACE=1keeps a test's copy and prints where); never point a server at a case directory itself. - Tear down servers by the PIDs you recorded (and their subtree) — never
pkillby name. A pattern sweep kills a sibling run's servers, and those deaths look exactly like the bug being hunted.
Known pitfalls (each cost a real debugging session)
- JS numbers mangle 64-bit values: parse such JSON with
JSON.rawJSONor a BigInt reviver; the CLI's answers name symbols by#<hex>locator strings for this reason. - Python-style truthiness does not port:
expect([]).toBeFalsy()fails — assertlengthexplicitly. - LSP positions are UTF-16 code units, or UTF-8 bytes or code points on a
server started with
positionEncoding; ASCII sources keep them equal to string indices — non-ASCII sources need real conversion. A test sending raw positions throughs.clientconverts them itself (SourceText.encode). Diagnostic.messageisstring | MarkupContent— narrow before.includes.- Child stdout/stderr backpressure is real: an undrained pipe blocks the
server;
spawnSynchas a 1MB defaultmaxBufferthat silently kills children. §is always a marker: a literal(right after an unnamed one is written§(), and case text never contains a literal§, comments included.- Include-completion cases use an include prefix unique to the case: the
pixi env's
$PREFIX/includeleaks into the search path and-nostdincdoes not stop it. Completion statements end with;— an unterminated statement drags the next marker into recovery context. - Windows file timestamps tick at ~15.6 ms: two touches inside one tick stat equal, so a test that needs distinct mtimes sets them explicitly.
- LMDB reads come from a resident snapshot: advance it after a write before
expecting visibility, and a test double wrapping
BlobDatabasemust forwardadvance_read_snapshot/retire_old_snapshot/growor the snapshot never moves. Probe blob keys go through the path pool's canonical spelling (Windows 8.3 short names hash differently). - Module tests stay green on lexical tokens alone even when the Tester writes no BMI at all: when touching the Tester compile path, check that a PCM is really produced.
- Under
-ffreestandingclang recognizes no library builtins (getBuiltinIDis 0): logic keyed on builtin recognition behaves differently in unit tests than under a hostedclice inspect. - A unit test runs in zest's worker process: one that crashes is reported
CRASHED under its own name, with what it printed, and the run goes on.
A debugger attached to
unittestssees only the runner — take a backtrace with--no-isolation --test-filter=Suite.Case, which runs the test in-process (lldb --batch -o run -k "bt 40" -- ...). - The Tester's driver is the
clang++on PATH: the cross-built platforms (arm64 Linux, x64 macOS, both Windows;build_osintest.yml) run their suites with only thetest-runenv active, so on arm64 Linux they compile against the runner's system libstdc++, not conda's, and on Windows with the runner's clang, which targets MSVC. A wrapper script namedclang++that execs the pixi clang with another--gcc-install-dirreproduces one of them locally.
Answers the index serves
Until a file's AST is current, the server answers its semantic tokens,
outline, folding ranges and document links from the index, and what the
editor shows must not change when the AST arrives. Every answers case checks
it on inspect (tests/README.md, "answers"): what the index's entries give
must be what the AST gives; it may leave things out, and what the lexer alone
gives where it has no entry does not count. A difference is a bug of one answer
or the other, fixed, never declared away. clice inspect <feature> <file> --index answers from the file's own TU index as the
server does; when a change touches these features or the index facts they
read, also compare it with the plain answer over real code — the
repository's sources, the libc++ and libstdc++ headers, LLVM's (a header
outside every project takes its command from a clice.toml above it whose
rule sets default_command) — and pin each difference that matters in a
case.
C++ unit tests (zest)
- Names of at most four words; what belongs in a unit test rather than a
case is in
tests/README.md, "Unit tests". - zest constructs a fresh suite object for every
ZEST_CASE: noreset()/clear()helpers, shared initialization goes in the suite's constructor (ZEST_SUITE(Name)declaresstruct NameTEST). A default-constructedWorkspacealready carries the real configuration defaults (Configguarantees it;BornValidDefaultspins it) — no defaults initialization is needed. - A check takes one expression and shows the operands of its top-level
comparison:
ZEXPECT(a == b),ZASSERT(result).&&,||, bitwise operators and shifts at the top level do not compile — split the check, or parenthesize it to check one bool. - A failed
ZASSERTends the test's worker process at once, without unwinding: it works the same in a coroutine, a helper or another thread, but the suite's destructor does not run — cleanup that must happen then goes in azest::FatalHook. Under--no-isolationit ends the whole run. - Filter with
--test-filter=<name>; a bare positional name is a usage error (exit 2). select("m")looks up a point while§(m)⟦...⟧registers only a range: a test that needs both annotates both (§(m)⟦§(m)foo⟧).
Tooling code (tools/)
- Framework > mature library > handwritten: vitest's own concurrency
(
test.concurrent,maxConcurrency) over a custom pool,jsdiffover a hand-rolled diff,util.parseArgsover a custom argv parser; say why a library is trustworthy (downloads, maintenance, already in the tree). The one exception is byte-level twin code — the C++/TS annotation parsers — whose contract is byte identity and which a library would break. tools/runs under node's strip-only TypeScript: erasable syntax only (no constructor parameter properties, no enums).- Naming: no abbreviated file names, no decorative section comments. New
modules join the subsystem directory they belong to (
tools/testing,tools/client,tools/docs,tools/protocol,tools/compat,tools/ecosystem); a new directory needs a new subsystem, not a new file. Framework and domain logic live intools/; test directories keep only what must be there (package.json, tsconfig, thin vitest glue). - The tools' own tests sit beside the code they test as
*.test.ts;npm test -w toolsruns them all, with no clice build.
04 同仓库更多 Skills
LLVM 升级指南
upgrade-llvm
在升级 xclang/LLVM(参数 = xclang 版本,例如 23.1.2.1)、修改 MODULE.bazel、.bazelrc、BUILD.bazel 或 bazel/,或重新生成 modules/ 之前阅读——适用于库版本升级之后,或 clice 需要某个其未导出的头文件或宏的情况。
问题工单分诊
triage
当用户要求对问题进行分诊时使用——使用 codex 对未分诊的问题进行分类,验证标签,并返回建议的标签以及活动摘要。只读;在分叉(forked)上下文中运行。
中文文档翻译与审校指南
translate-docs
在翻译、审查或编辑任何 docs/zh 页面之前阅读——涵盖 clice 的术语表与页面约定,以及 clice-io/docs 的共享翻译规则。
clice 测试套件运行
test
运行 clice 测试套件,除非确实有必要本地运行,否则应在远程机器(box)上执行;另附在 Windows 上测试的方法。可选参数 = 套件(unit | cases | all,默认 all)、构建类型(Debug | RelWithDebInfo,默认 RelWithDebInfo)以及运行构建的机器 id。该技能在 fork 上下文中运行,仅返回摘要。
PR 审查意见修复与解决
resolve-comments
在已打开 PR 的每一轮跟进中使用——拉取其中未解决的审查讨论线程,在工作树中修复并解决它们,然后返回一份简明的摘要。
版本发布与崩溃日志符号化
release
在进行任何发布工作之前阅读——包括即时构建、夜间版本、稳定标签、发布上线、发布工作流——或用于符号化用户的崩溃日志。