Skip to content
Myr

Hold datekit's run block to main in its test, rerun the rules test when an example's config folder changes, and add the remote step to its README

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Review of 507 against its issue (Spec) and AGENTS.md (Standards). - turbo.json: a `@repo/rules#test` task (a copy of `test`, as `@repo/project#test` is) adds `$TURBO_ROOT$/examples/*/.*/**` to its inputs and leaves `examples/*/.env*` out. The rules test reads datekit's config folder, outside its package, so its hash ignored it: with datekit's deciders changed, `turbo run test` replayed a cached pass and `verify` stayed green. Checked: a config edit now changes the task's hash. The glob takes every example's dot-folders without spelling the config folder's name, and the exclusion keeps turbo from reading a closed env file. A tightening, outside 507's territory, applied as 067465b did for migrations; it covers 508's config folder too. - packages/config/test/example-datekit.test.ts: a second test runs the run block from project.ts as the Checker runs it, under `sh -c` in the example. Every lane passes on main over the four library suites (a lane red on main makes every answer VerifierBlocked), and each ask's check, run alone by the `test` command with its path for `{path}`, fails its one test by an assertion (NotRedFirst otherwise). Before, nothing tested the `unit` lane the branch added. The first test now runs `bun test` through the same `sh -c` helper. - Red by assertion, planted: a whole-suite `unit` lane fails the new test; a fixed `ordinal` fails both tests. - examples/datekit/README.md: the contributing steps add `git remote add myr <remote>` after `claim`, as the claim's output and the generated AGENTS.md block do; without it the push line fails. - Checked by hand, no change: with fixes for all three asks in a scratch copy, 37 of 37 pass and the unit lane stays green; the platform's `diagnose` gives each ask check `Failed` with an assertion signature, and `weaknessesOf` finds no weak shape.

authored by oscabriel · committed by oscabriel · parent 8bd2f7c · Browse files · 3 files+130 added−23 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+130 added−23 removed

  • tests:+119 added−23 removed
  • other:+11 added−0 removed

3 files+130 added−23 removed

modified:examples/datekit/README.md+1 added
modified:packages/config/test/example-datekit.test.ts+119 added-23 removed
1 unmodified line
2 * The datekit example (issue 507), run as the project it pretends to be:3 * `bun test` inside `examples/datekit` is red on main for exactly the three4 * tests its asks name as their checks, each by an assertion rather than a5 * load error (what red first in GLOSSARY.md asks of a check), and green for6 * every other test. The example is a Bun project of its own, outside the7 * workspaces (spec D21), so it is run as a child process, the way the8 * platform's Checker runs a project's own test command.6 * every other test. Its run block holds on main too: every lane passes, and7 * each ask's check, run alone by the block's test command, is red by an8 * assertion. The example is a Bun project of its own, outside the9 * workspaces (spec D21), so each command runs as a child process under10 * `sh -c`, the way the platform's Checker runs a project's commands.11 */12import { NodeServices } from "@effect/platform-node";13import { describe, expect, it } from "@effect/vitest";14import { Effect, FileSystem, Path, Stream } from "effect";
58 unmodified lines
73// (`kinds.fix.ask({ path: "test/asks/<id>.test.ts", … })`), which the kind74// makes the ask's `RedThenGreen.path`.75const CHECK_PATH = /\bpath:\s*"(?<path>[^"]+)"/u;7677// The run block as project.ts writes it (the rules test holds it to the78// evaluated policy): the command that runs one check file, with `{path}`79// in it, and the lanes every answer must pass, `checks: { unit: "…" }`.80const TEST_COMMAND = /\btest:\s*"(?<command>[^"]*\{path\}[^"]*)"/u;8182const LANES = /\bchecks:\s*\{(?<lanes>[^}]*)\}/u;8384const LANE = /(?<lane>\w+):\s*"(?<command>[^"]+)"/gu;8586/** A closing count bun prints (` 3 fail`), or 0 when it prints none. */87const countOf = (output: string, word: string) =>88 Number(89 new RegExp(`^\\s*(?<count>\\d+) ${word}$`, "mu").exec(output)?.groups
46 unmodified lines
136137const text = <E>(bytes: Stream.Stream<Uint8Array, E>) =>138 bytes.pipe(Stream.decodeText(), Stream.mkString);139140/** Runs `command` inside the example under `sh -c`, as the Checker runs a lane. */129/** Runs `bun test` inside the example, as its own `package.json` does. */130const bunTest = Effect.scoped(131 Effect.gen(function* () {132 const path = yield* Path.Path;133 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;134 const root = yield* repoRoot;141const inExample = (command: string) =>142 Effect.scoped(143 Effect.gen(function* () {144 const path = yield* Path.Path;145 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;146 const root = yield* repoRoot;147136 const child = yield* spawner.spawn(137 ChildProcess.make("bun", ["test"], { cwd: path.join(root, example) })138 );148 const child = yield* spawner.spawn(149 ChildProcess.make("sh", ["-c", command], {150 cwd: path.join(root, example),151 })152 );153140 const [stdout, stderr, exitCode] = yield* Effect.all(141 [text(child.stdout), text(child.stderr), child.exitCode],142 { concurrency: "unbounded" }143 );154 const [stdout, stderr, exitCode] = yield* Effect.all(155 [text(child.stdout), text(child.stderr), child.exitCode],156 { concurrency: "unbounded" }157 );158145 return {146 exitCode,147 output: `${stdout}\n${stderr}`.replaceAll(ANSI, ""),148 } satisfies BunRun;149 })150);159 return {160 exitCode,161 output: `${stdout}\n${stderr}`.replaceAll(ANSI, ""),162 } satisfies BunRun;163 })164 );165166/** The example's run block, read from its project file. */167const runBlock = Effect.gen(function* () {168 const fs = yield* FileSystem.FileSystem;169 const path = yield* Path.Path;170171 const source = yield* fs.readFileString(172 path.join(yield* repoRoot, example, Brand.configDir, "project.ts")173 );174175 const lanes = Array.from(176 (LANES.exec(source)?.groups?.lanes ?? "").matchAll(LANE),177 ({ groups }) => ({178 command: groups?.command ?? "",179 lane: groups?.lane ?? "",180 })181 );182183 return { lanes, test: TEST_COMMAND.exec(source)?.groups?.command ?? "" };184});185186/**187 * Each ask file in the example's config folder, and the check file it names;188 * none when the folder is missing.189 */
33 unmodified lines
223 it.live(224 "is red on main for exactly its three asks' checks, each by an assertion, and green elsewhere",225 () =>226 Effect.gen(function* () {193 const run = yield* bunTest;227 // The example's own `package.json` test script.228 const run = yield* inExample("bun test");229 const report = readReport(run.output);230 const checks = yield* askChecks;231232 expect(checks.map(({ file }) => file)).toStrictEqual([
37 unmodified lines
270 // One `bun test` over a small library: well under a second alone. The271 // limit catches a hang while turbo runs every package's tests at once.272 30_000273 );274275 it.live(276 "holds its run block on main: every lane green, and each ask's check red alone by an assertion",277 () =>278 Effect.gen(function* () {279 const { lanes, test } = yield* runBlock;280 const checks = yield* askChecks;281282 // A lane red on main refuses every answer (`VerifierBlocked`), so the283 // suite every answer keeps green leaves the open asks' checks out and284 // runs the four the library keeps green.285 const laneRuns = yield* Effect.forEach(lanes, ({ command, lane }) =>286 Effect.map(inExample(command), (run) => {287 const report = readReport(run.output);288289 return {290 errors: report.errors,291 exitCode: run.exitCode,292 failed: report.failed,293 files: report.ran.files,294 lane,295 };296 })297 );298299 expect(laneRuns).toStrictEqual([300 { errors: 0, exitCode: 0, failed: 0, files: 4, lane: "unit" },301 ]);302303 // The platform opens an ask only when its check is red first304 // (`NotRedFirst` otherwise): the test command, with the check's path305 // for `{path}`, fails its one test by an assertion.306 const checkRuns = yield* Effect.forEach(checks, ({ check }) =>307 Effect.map(inExample(test.replaceAll("{path}", check)), (run) => {308 const report = readReport(run.output);309310 return {311 errors: report.errors,312 exitedNonZero: run.exitCode !== 0,313 failing: report.files314 .filter(({ failed }) => failed.length > 0)315 .map(howFailed),316 };317 })318 );319320 expect(checkRuns).toStrictEqual(321 [322 "test/asks/add-months-clamp.test.ts",323 "test/asks/format-ordinal.test.ts",324 "test/asks/parse-iso-week.test.ts",325 ].map((file) => ({326 errors: 0,327 exitedNonZero: true,328 failing: [{ assertion: true, file, loaded: true, tests: 1 }],329 }))330 );331 }).pipe(Effect.provide(NodeServices.layer)),332 // Four `bun test` runs over a small library, one after another.333 30_000334 );335});
modified:turbo.json+10 added