Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/oracles.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Oracles

on:
pull_request:
push:
branches:
- main

permissions:
contents: read

jobs:
oracle-laws:
name: Oracle laws
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up toolchain
uses: moonrepo/setup-toolchain@v0
with:
moon-version: "2.6.5"
auto-install: true

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Check oracle laws
run: moon exec --ignore-ci-checks --force cssforge:oracles

- name: Upload gap report
if: always()
uses: actions/upload-artifact@v4
with:
name: oracle-gap-report
include-hidden-files: true
path: |
.tmp/oracle-reports/**/summary.md
.tmp/oracle-reports/**/results.json
.tmp/oracle-reports/**/test-output.log
.tmp/oracle-reports/**/error.log
.tmp/oracle-reports/**/stream.log
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ convert.ts
TODO.md
.worktrees
.artifact-build-*

/.tmp/oracle-reports/
15 changes: 15 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ standard library or writing code from first principles.
- Before handing off implementation, test, build, or tooling changes, use `$code-review`.
Documentation and agent-instruction changes require it only when explicitly requested.

## Oracle tests

Run `moon run cssforge:oracles` when changing behavior covered by an oracle. The
[contributor guide](packages/cssforge/oracles/README.md) explains the reports and replay.
Agree on new or changed laws with a maintainer. Reproduce defects against the
public API and make the oracle fail on unchanged production before fixing it.

Read the relevant installed guide in full before oracle work. The paths are
relative to the repository root:

- Exploring behavior or proposing laws: `packages/cssforge/node_modules/@tanstack/oracles/skills/oracles-explore/SKILL.md`
- Writing or changing oracles or their owned production code: `packages/cssforge/node_modules/@tanstack/oracles/skills/oracles-design/SKILL.md`
- Reviewing or evaluating a review: use `oracles-review` or `oracles-evaluate-review` under the same `skills/` directory.
- Changing setup or upgrading the dependency: use `oracles-setup` under the same `skills/` directory.

## Library architecture

- Keep token transformation, validation, normalization, and generation in framework-neutral
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ moon run cssforge:jsr-dry-run
`cssforge:smoke-test` packs the package and installs that tarball in clean npm and pnpm
projects, and `cssforge:jsr-smoke` runs the JSR entry points with Node.

Use `moon run cssforge:oracles` to check generated token behavior with the
[oracle tests](https://github.com/Hebilicious/cssforge/blob/main/packages/cssforge/oracles/README.md).

## Quick Start

1. Create a configuration file (`cssforge.config.ts`):
Expand Down
3 changes: 3 additions & 0 deletions packages/cssforge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ moon run cssforge:jsr-dry-run
`cssforge:smoke-test` packs the package and installs that tarball in clean npm and pnpm
projects, and `cssforge:jsr-smoke` runs the JSR entry points with Node.

Use `moon run cssforge:oracles` to check generated token behavior with the
[oracle tests](https://github.com/Hebilicious/cssforge/blob/main/packages/cssforge/oracles/README.md).

## Quick Start

1. Create a configuration file (`cssforge.config.ts`):
Expand Down
8 changes: 8 additions & 0 deletions packages/cssforge/eslint.oracles.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import oracles from "@tanstack/eslint-plugin-oracles";
import parser from "@typescript-eslint/parser";

export default [
oracles.configs.recommended,
oracles.configs.production,
{ files: ["oracles/**/*.ts", "src/**/*.ts"], languageOptions: { parser } },
];
39 changes: 39 additions & 0 deletions packages/cssforge/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ tasks:
- "check"
- "src"
- "tests"
- "oracles"
- "scripts"
- "package.json"
- "tsconfig.json"
- "vitest.config.ts"
- "vitest.oracles.config.ts"
- "eslint.oracles.config.mjs"
- "tsup.config.ts"
- "jsr.json"
- "--linter-enabled=false"
Expand All @@ -55,10 +58,13 @@ tasks:
inputs:
- "src/**/*"
- "tests/**/*"
- "oracles/**/*"
- "scripts/**/*"
- "package.json"
- "tsconfig.json"
- "vitest.config.ts"
- "vitest.oracles.config.ts"
- "eslint.oracles.config.mjs"
- "tsup.config.ts"
- "jsr.json"
- "src/version.ts"
Expand All @@ -71,10 +77,13 @@ tasks:
- "check"
- "src"
- "tests"
- "oracles"
- "scripts"
- "package.json"
- "tsconfig.json"
- "vitest.config.ts"
- "vitest.oracles.config.ts"
- "eslint.oracles.config.mjs"
- "tsup.config.ts"
- "jsr.json"
- "--linter-enabled=false"
Expand All @@ -89,13 +98,15 @@ tasks:
- "check"
- "src"
- "tests"
- "oracles"
- "scripts"
- "--formatter-enabled=false"
- "--assist-enabled=true"
- "--enforce-assist=true"
inputs:
- "src/**/*"
- "tests/**/*"
- "oracles/**/*"
- "scripts/**/*"
- "/biome.json"
options:
Expand All @@ -111,6 +122,8 @@ tasks:
inputs:
- "src/**/*"
- "tests/**/*"
- "oracles/**/*"
- "vitest.oracles.config.ts"
- "scripts/**/*"
- "tsconfig.json"
- "/tsconfig.base.json"
Expand Down Expand Up @@ -143,6 +156,32 @@ tasks:
- "/tsconfig.base.json"
options:
runInCI: "always"
oracle-lint:
command: "eslint"
args: ["--config", "eslint.oracles.config.mjs", "oracles", "src"]
inputs:
- "oracles/**/*"
- "src/**/*"
- "eslint.oracles.config.mjs"
- "package.json"
- "/pnpm-lock.yaml"
options:
runInCI: false
oracles:
command: "node"
args: ["./scripts/check-oracles.ts"]
deps: ["~:oracle-lint", "~:typecheck"]
inputs:
- "oracles/**/*"
- "src/**/*"
- "scripts/check-oracles.ts"
- "vitest.oracles.config.ts"
- "package.json"
- "/pnpm-lock.yaml"
options:
# The Oracles workflow runs this explicitly so it can upload each report.
runInCI: false
cache: false
test-watch:
command: "vitest"
options:
Expand Down
37 changes: 37 additions & 0 deletions packages/cssforge/oracles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Oracle tests

Run from the workspace root after `pnpm install`:

```sh
moon run cssforge:oracles
```

The task lints and type-checks the oracle files, then runs `oracle-gaps` with a
fixed seed. The baseline checks real CSS Forge against independently computed
expected results. The gap check makes small changes to copies of the source
and reports which changes the oracles detect.

Open the printed `summary.md` for failing laws, shrunk inputs, replay commands,
and gaps. The replay paths are relative to `packages/cssforge`. Rerun the Moon
task from the workspace root to verify a fix with the same seed. Each run
writes to a new directory under `.tmp/oracle-reports/`. In
GitHub Actions, download the `oracle-gap-report` artifact. A failed or
nondeterministic baseline fails the job. The mutation gaps appear in the
report for review.

## Add or change a law

1. Probe the exported API and identify the promise in the docs, a test, or a
maintainer decision. Ask a maintainer to approve new or changed laws.
2. Add the law and its source to an `*.oracle.test.ts` file here. Generate inputs,
compute expected results independently, and call the public API in the
driver. Include boundary cases and a calibration that the check must reject.
3. For a bug fix, run the task on the unchanged source first. Keep the failing
input and run the same check after the fix. Inspect gaps for observations or
inputs the law should cover.
4. If you add an owned source file, include it in the runner’s `--source` list
in [check-oracles.ts](../scripts/check-oracles.ts). The oracle’s `owns` list
declares the functions subject to the gap check.

See [AGENTS.md](../../../AGENTS.md#oracle-tests) for the installed Oracles guides
on exploration, design, and review.
3 changes: 3 additions & 0 deletions packages/cssforge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@
"devDependencies": {
"@acid-cat/cli": "0.13.0",
"@biomejs/biome": "2.4.2",
"@tanstack/eslint-plugin-oracles": "0.0.1",
"@tanstack/oracles": "0.0.1",
"@types/node": "24.3.0",
"@typescript-eslint/parser": "^8.56.0",
"eslint": "^9.39.2",
"fast-check": "4.11.0",
"mdbox": "0.1.1",
"tsup": "8.5.0",
Expand Down
58 changes: 58 additions & 0 deletions packages/cssforge/scripts/check-oracles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { spawnSync } from "node:child_process";
import { mkdirSync, mkdtempSync, readFileSync } from "node:fs";
import { join, resolve } from "node:path";
import { fileURLToPath } from "node:url";

const packageRoot = resolve(import.meta.dirname, "..");
const reports = resolve(packageRoot, "../../.tmp/oracle-reports");
mkdirSync(reports, { recursive: true });
const out = mkdtempSync(join(reports, "run-"));
const cli = fileURLToPath(
new URL(
"./oracle-gaps/index.mjs",
import.meta.resolve("@tanstack/oracles/package.json"),
),
);

const run = spawnSync(
process.execPath,
[
cli,
"--package",
packageRoot,
"--source",
"src/lib.ts,src/generator.ts,src/modules/colors.ts",
"--config",
"vitest.oracles.config.ts",
"--seed",
"47",
"--contexts",
"4",
"--out",
out,
],
{ stdio: "inherit" },
);
if (run.error) throw run.error;
if (run.status !== 0) {
throw new Error(`oracle-gaps failed with ${run.signal ?? run.status}`);
}

// The CLI returns zero when analysis completes, including when the baseline fails.
const report: unknown = JSON.parse(readFileSync(join(out, "results.json"), "utf8"));
if (
typeof report !== "object" ||
report === null ||
!("provisional" in report) ||
report.provisional !== false ||
!("baseline" in report) ||
!Array.isArray(report.baseline) ||
report.baseline.length === 0 ||
!("nondeterministic" in report) ||
!Array.isArray(report.nondeterministic) ||
report.nondeterministic.length > 0
) {
throw new Error(
`Oracle baseline failed, was nondeterministic, or is missing. See ${out}`,
);
}
44 changes: 0 additions & 44 deletions packages/cssforge/tests/key-collision.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,6 @@ test("generator - variantNameOnly themes may reuse a key in different scopes", (
test("generator - unscoped declarations that share a key are rejected", () => {
// Every case below lands in `:root`, so one declaration overwrites the other.
const unscoped: Array<[string, () => unknown, string]> = [
[
"two themes",
() =>
generateCSS(
defineConfig({
colors: {
palette,
theme: {
light: { value: variantTheme() },
other: { value: variantTheme() },
},
},
}),
),
'Token key collision: "theme.light.background.primary" and "theme.other.background.primary" both generate "--primary". Rename one of the configuration paths.',
],
[
"a theme and the spacing module",
() =>
Expand Down Expand Up @@ -220,34 +204,6 @@ test("generator - unscoped declarations that share a key are rejected", () => {
}
});

test("generator - an explicit :root selector collides inside a shared at-rule", () => {
const error = thrownError(() =>
generateCSS(
defineConfig({
colors: {
palette,
theme: {
light: {
value: variantTheme(),
settings: {
atRule: "@media (prefers-color-scheme: dark)",
selector: ":root",
},
},
dark: {
value: variantTheme(),
settings: { atRule: "@media (prefers-color-scheme: dark)" },
},
},
},
}),
),
);
expect(error.message).toEqual(
'Token key collision: "theme.light.background.primary" and "theme.dark.background.primary" both generate "--primary". Rename one of the configuration paths.',
);
});

test("generator - differing wrappers may share a key", () => {
// A wrapper is part of the scope identity, so the same name under two
// different wrappers does not overwrite. Covers both modules and both
Expand Down
2 changes: 2 additions & 0 deletions packages/cssforge/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
"include": [
"src/**/*.ts",
"tests/**/*.ts",
"oracles/**/*.ts",
"scripts/**/*.ts",
"vitest.config.ts",
"vitest.oracles.config.ts",
"tsup.config.ts"
]
}
Loading
Loading