Skip to content

Latest commit

 

History

History
102 lines (88 loc) · 26.4 KB

README.md

File metadata and controls

102 lines (88 loc) · 26.4 KB

Runner conformance suite

Fixture problems in the normal problem format (problem-format) that every runner must handle the same way. cstudy verify --conformance runs every fixture's reference approaches in every language its meta.yaml lists (the four core languages by default; Go and Rust where it lists go or rust), compares each runner outcome with expectations.json (schema), and generates and compiles the stub of every fixture. Spec: runners.

Layout

Path Scope Content
<slug>/meta.yaml, <slug>/tests.json Shared by every runner Signature and cases; a change affects every language the fixture lists
<slug>/solutions/<approach>.py Python runner Reference approach
<slug>/solutions/<approach>.ts TypeScript runner Reference approach (named export)
<slug>/solutions/<approach>.java, .kt JVM runner Reference approach without a package line; the materializer prepends it
<slug>/solutions/<approach>.go Go runner Reference approach in package <snake_slug>, like the stub; copied unchanged into a package of its own
<slug>/solutions/<approach>.rs Rust runner Reference approach as the stub declares it (pub fn, or pub struct with impl); built as a #[path] module of the problem's harness crate
<slug>/starter/, <slug>/solutions/<approach>/ The runner of the project fixture's one language A project fixture: the starter, and the approach's overlay on it. cstudy verify --conformance builds the starter with the overlay and the generated test file of every level (reference materialization) and runs it as a project job; a project fixture has no generated stub
expectations.json Shared by every runner Expected outcome per fixture and approach

Outcomes

Status Meaning
pass The runner reports ok and the fixture's comparator accepts the output; stdout, when given, must match exactly
error The runner reports error; message, op_index and partial_output, when given, must match exactly
invalid_output The runner reports invalid_output (any reason text)
timeout The CLI hang guard kills the runner on this case, and the later cases still run
load_error The runner reports load_error for the job instead of any case
fail Stress cases: the run completed but broke an invariant or final.expected
stalled Stress cases: workers were still unfinished at the deadline; progress names a worker inside an op

A project fixture's cases run as a grading job at its last level and take the outcomes above, its stress cases included. A project's broken overlay (solutions/broken/<id>/) runs as approach broken-<id>, built on the starter and the reference's overlay. When its expectation lists tests, the reference's native suite also runs as a suite job, and every test it reports must be listed, by test id, and reported once with its status; message and stdout, when given, must match exactly:

Test status Meaning
ok The test passed
failed An assertion failed; message is the framework's failure text
error Any other exception, a failing fixture, or a test file that does not import; message is the exception's message
skipped The framework skipped it; message is the reason
timeout The CLI hang guard ended the runner during the test, and the suite restarted without it
crashed The runner process ended during the test, and the suite restarted without it

A Rust suite runs each test as a process of its own: a panic is failed, with the panic's message and location relative to the project folder; a test file that does not compile is one error test named by its path; a hang or a crash ends only that test's process.

Stress cases run runs times per variant (default 10; JVM fixtures run once per thread kind). With pass, at most max_failed runs may fail (default 0); with any other status, at least min_failed runs (default: every run) must fail with that status, and message, op_index and phase must match each of them. deterministic repeats the first seed once more and requires both runs of that seed to produce the same run record and the other seeds at least two distinct records; restart_requested requires the runner to ask for a restart after a run of the case. A fixture runs only in the languages its meta.yaml lists, which is also how a runner skips what it does not support yet: Go lists every fixture that is not a project, but conformance-stress-async-determinism, which stays Python and TypeScript: it tests the async model, and Go and Rust run the threads model only. Rust lists the same fixtures as Go except conformance-cyclic-list and conformance-ref-of-list, which cstudy verify S13 keeps out of Rust for good: an Option<Box<ListNode>> cannot be cyclic, and ref_of cannot hand out a second reference to one of its nodes (ADR 0012).

A fixture's meta.yaml has a languages line only where it differs from the default of all six languages: conformance-cyclic-list and conformance-ref-of-list leave out Rust (an Option<Box<ListNode>> has no cyclic list and no ref_of), conformance-stress-async-determinism lists Python and TypeScript (the async determinism check), conformance-stress-leak leaves out TypeScript (the leak check needs threads), and each project fixture lists its one language. Fixtures load as catalog content, so the default is all six, not the four core languages of a workspace problem.

What each approach does

Every approach is written once per language, in that language's idiomatic form for the stub signature.

Fixture Approach Behavior Expected
conformance-types identity TypeEcho(label) ignores label; every echo* method returns its argument unchanged; noop returns nothing. Every DSL type except decimal and date pass
conformance-decimal-date-types identity The same echo methods for decimal and date, in scalars, arrays, matrices and lists; a fixture of its own so that a runner can join the suite before it supports them. Go echoes decimal.Decimal and time.Time, Rust rust_decimal::Decimal and chrono::NaiveDate; the extremes (28 nines, 28 places, years 0001 and 9999) fit both pass
conformance-decimal-date arithmetic DecimalDates adds and totals decimals of mixed scale, rounds to cents half up and half even, prorates a premium (half up), adds days to a date across leap days and counts the days between two dates; inputs keep their scale and outputs are canonical (2500.00 comes back as 2500). Go rounds with Round and RoundBank, prorates with DivRound (one exact rounding) and counts days through Unix seconds; Rust rounds with round_dp_with_strategy (MidpointAwayFromZero, MidpointNearestEven) after a 28-digit division, and counts days with NaiveDate subtraction pass
conformance-function identity echoHTTPCodes returns firstValue unchanged pass
conformance-exception raises failWith throws with message as the exception message: Python RuntimeError, TypeScript Error, Java IllegalStateException, Kotlin error(...), Go panic(message), Rust panic!("{message}") error with that message
conformance-op-error counts increment adds 1 to a counter starting at 0 and returns it; fail throws (Go and Rust: panics) with message counter failure fails case: error at op_index 3 with partial_output [null, 1, 2]
conformance-non-finite multiplies scale returns value * factor (1e308 * 10 overflows to infinity) overflow case: invalid_output
conformance-cyclic-list identity echoList returns head unchanged cyclic case: invalid_output
conformance-missing-symbol misnamed Defines echoNumberTypo (Python and Rust echo_number_typo) with the same signature instead of echoNumber; in Go the generated registration and in Rust the generated bridge do not compile, so the runner is rebuilt without the target load_error
conformance-hang spins waitFor loops forever when value is negative, else returns value hang case: timeout
conformance-stdout prints shout prints text on its own line to standard output (print, console.log, System.out.println, println, fmt.Println, println!), then returns text pass with stdout conformance output\n
conformance-ref-of-list identity pickNode returns node unchanged pass
conformance-ref-of-list new-node pickNode returns a new node with node's value (as: index of a node outside head) invalid_output
conformance-ref-of-tree identity pickTreeNode returns node unchanged pass
conformance-output-from sorts sortValues sorts values ascending in place and returns nothing pass
conformance-no-alias deep-copy copyList builds new nodes with the same values pass
conformance-no-alias returns-input copyList returns head unchanged invalid_output, except empty: pass
conformance-stress-counter atomic increment adds 1 under a lock (AtomicInteger on the JVM, sync.Mutex in Go, Mutex<i32> in Rust) and returns the new count s1: pass 10 of 10
conformance-stress-counter racy increment reads the count on one line and writes it on the next, returning the count it wrote. TypeScript awaits between them. Java, Kotlin, Go and Rust yield to the scheduler between them (Thread.yield(), runtime.Gosched(), std::thread::yield_now()): they have no injected yields inside user code, and on a busy machine the OS can run their workers one after another, so a window of a few instructions lost no update in up to 2 of 10 runs. A yield through the OS (Thread.yield(), yield_now()) costs a scheduler round trip on a saturated machine, so the four run 1000 increments per worker, not 4000: at a load of about 100, 4000 outlasted the 5 s deadline in 2 or 3 of 10 platform-thread runs. In Go it is a plain data race, in Rust a relaxed atomic load and a separate store, since safe Rust has no data race. Python relies on the runner's injected yields s1: fail (distinct) in at least 9 of 10
conformance-stress-stall never-opens enter waits on a gate nobody opens (Event, CountDownLatch, a promise that never settles, a channel nobody closes, a Condvar nobody notifies) s1: stalled
conformance-stress-worker-error throws-at step returns index, and throws failed at 100 when index is 100 s1: error, phase worker, op 100
conformance-stress-sections locked lock and unlock use a real mutex (an async one with a waiter queue in TypeScript, sync.Mutex in Go, a flag under a Mutex with a Condvar in Rust, whose MutexGuard cannot outlive lock) s1: pass 10 of 10, no probe violations
conformance-stress-sections unlocked lock and unlock do nothing s1: fail (section) in at least 9 of 10
conformance-stress-async-determinism interleaves append yields once, appends and returns the length (Python async and TypeScript only) s1: pass, identical records for one seed, distinct across seeds
conformance-stress-leak ignores-interrupt spin loops forever ignoring interrupts, fail throws (threads only; Go and Rust have no interrupt at all, and neither a goroutine nor a thread can be stopped from outside). In Go and Rust, fail first waits until spin runs: their runners stop a worker before its next op, so a run that failed before the spinner's first op would leave nothing running and ask for no restart s1: error, then restart_requested; s2 still runs and passes
conformance-project-python reference A two-file Python project: the entry module store/inventory.py imports its sibling store/labels.py by package path and by relative path, and raises ImportError if the two imports load the module twice; Inventory adds stock counts and labels them pass
conformance-suite-pytest reference Probe.ping returns pong; the overlay adds tests/test_statuses.py, with a test that passes, one that hangs, one that fails an assertion, one that ends the process (os._exit(3)), one that raises RuntimeError("conformance failure") and one that prints. limits.hang_guard_ms is 1000, so the hang costs a second pass; tests: the generated test_ex1 and test_passes ok, test_hangs timeout, test_fails_an_assertion failed, test_ends_the_process crashed, test_raises error with its message, test_prints ok with stdout conformance output\n
conformance-project-typescript reference A two-file TypeScript project, an ES module package with no node_modules: the entry src/inventory.ts imports its sibling src/labels.ts by relative path and through the package's own imports map (#store/* to ./src/*), and throws if the two imports load the module twice; Inventory adds stock counts and labels them pass
conformance-suite-node-test reference Probe.ping returns pong; the overlay adds tests/statuses.test.ts, with a test that passes, one that hangs, one that fails an assertion, one that ends the process (process.kill(process.pid, "SIGKILL"), since the runner turns process.exit into an error), one that throws Error("conformance failure") and one that prints. limits.hang_guard_ms is 1000, so the hang costs a second pass; tests: the generated ex1 and passes ok, hangs timeout, fails an assertion failed, ends the process crashed, raises error with its message, prints ok with stdout conformance output\n
conformance-project-java reference A Java project across packages: the entry store.Inventory uses store.Counts, a class of its own package that the overlay adds, and store.labels.Labels, a class of a subpackage that the starter holds; Inventory adds stock counts and labels them pass
conformance-project-kotlin reference The same project in Kotlin, with Counts internal and Labels an object pass
conformance-suite-junit-java reference Probe.ping returns pong; the overlay adds StatusesTest.java, with a test that passes, one that hangs, one that fails an assertion (assertEquals), one that ends the process (System.exit(3)), one that throws IllegalStateException("conformance failure"), one that prints, a @Disabled("not ready") test, one whose assumption fails and a parameterized test of two invocations, and BrokenSetupTest.java, whose @BeforeAll throws setup failure. limits.hang_guard_ms is 1000 pass; tests, by file-first id: the generated Level1Test.java::ex1 and passes ok, hangs timeout, failsAnAssertion failed with expected: <ping> but was: <pong>, endsTheProcess crashed, raises error with its message, prints ok with stdout conformance output\n, disabled skipped with not ready, assumes skipped with aborted: Assumption failed: no network, counts[1] and counts[2] ok, and BrokenSetupTest.java reported once as an error with setup failure, never again after a restart
conformance-suite-junit-kotlin reference The same suite in Kotlin, with kotlin.test's assertions, exitProcess(3) and error(...) As in Java, with .kt files
conformance-project-go reference A Go project, module conformance-project-go: the entry store.go declares Inventory in the root package, which spreads over two files and imports the package labels of its module by import path and the vendored decimal module, which a grading build reaches through the project's own go.work pass
conformance-suite-go-test reference Probe.Ping returns pong; the overlay adds tests/statuses_test.go, with a test that passes, one that fails an assertion, a table whose subtest bad fails, one that panics with conformance failure, one that prints, one that ends the process (os.Exit(3)) and one that hangs (time.Sleep), and broken/broken_test.go, which does not compile. The panic and the exit each end the test binary, and its package runs again without the tests reported so far; limits.hang_guard_ms is 1000, so the hang costs about two seconds with the runner's one second of quiet pass; tests: the generated TestEx1, TestPasses, TestTable/ok and TestPrints ok, the last with stdout conformance output\n; TestFailsAnAssertion, TestTable/bad and TestTable failed; TestPanics error with its message; TestEndsTheProcess error; TestHangs timeout; the package conformance-suite-go-test/broken error
conformance-project-rust reference A multi-file Rust crate shop: the entry module src/stock/inventory.rs uses its sibling src/stock/labels.rs by super:: path and by crate:: path, and src/lib.rs re-exports Inventory at the crate root; the harness reaches the crate through a path dependency under another package name. Inventory adds stock counts and labels them pass
conformance-suite-cargo reference Probe::ping returns pong; the overlay adds tests/statuses.rs, with a test that passes, one that fails an assert_eq!, one that panics with conformance failure, one that hangs, one that aborts (std::process::abort), one that prints, one ignored with the reason conformance reason and one should_panic test, and tests/broken.rs, which does not compile. Each test runs as a process of its own, so the hang and the abort end only their own test. limits.hang_guard_ms is 1000, so the hang costs a second pass; tests: tests/broken.rs error, the generated ex1 and passes ok, fails_an_assertion failed, panics failed with its message and location, hangs timeout, aborts crashed, prints ok with stdout conformance output\n, is_ignored skipped with its reason, panics_as_expected ok
conformance-project-clock-go reference A Go project on the virtual clock (project.clock: virtual), graded by its package's test binary with each case in a testing/synctest bubble: Receive waits on a timer for a message that Publish hands over, Sleep returns the time it slept as the time package measures it, Hold waits on a channel nobody sends to, Jam locks a mutex it holds and Leave starts a goroutine that never ends. The cases use @advance, @spawn, @join and @now; advance and spawn-join are visible, so their generated synctest tests run natively on the reference, and the cases that deadlock, jam or leave a goroutine are hidden. limits.hang_guard_ms is 1000 pass, and its generated tests ok, but deadlock stalled at op 3 (@join r1): deadlock at 2000 ms and leftover stalled at op 2 (@now): the case ended with goroutines still blocked at 0 ms, each followed by restart_requested, and jam timeout; the cases after each still run
conformance-project-clock-python reference A Python project on the virtual clock, each case graded on an asyncio loop of cs_support.virtual_clock: publish hands a message to receive, an async def that waits for one under asyncio.timeout; sleep returns the time it slept as the loop's clock measures it; race starts one task per name that all wake at the same instant and returns the order they woke in, which seed 0 decides (bacd for abcd); hold waits on an event nobody sets; jam takes a threading.Lock it holds; leave starts a task that never ends and strand a thread that never ends. ex1, advance, spawn-join and ties are visible, so their generated async def tests run natively on the reference with the plugin cs_support.virtual_clock, which pyproject.toml loads; seed 0 gives ties the same order there. limits.hang_guard_ms is 1000 pass, and its generated tests ok, but deadlock stalled at op 3 (@join r1): deadlock at 2000 ms with no restart, jam timeout and strand followed by restart_requested; leftover passes, since the task left waiting is cancelled when the case ends; the cases after each still run
conformance-project-clock-typescript reference A TypeScript project on the virtual clock, each case graded on node:test's mock timers through runners/typescript/lib/virtual-clock.ts, a copy of which the starter holds as tests/virtual-clock.ts: publish hands a message to receive, which waits for one on setTimeout; sleep returns the time it slept as Date.now() reads it; steps chains sleeps of the static import of node:timers/promises and returns the time each one ended; race starts sleeps that all end at the same instant and returns the order they ended in, the order they started (abcd); hold returns a promise nobody settles; spin never returns; leave leaves a promise and a timer pending. ex1, advance, spawn-join, chain and ties are visible, so their generated tests run natively on the reference through the starter's tests/virtual-clock.ts. limits.hang_guard_ms is 1000 pass, and its generated tests ok, but deadlock stalled at op 3 (@join r1): deadlock at 2000 ms with no restart and spin timeout; chain gives [10, 20, 30] and leftover passes, since what is pending when a case ends is dropped; the cases after each still run
conformance-project-clock-kotlin reference A Kotlin project on the virtual clock, each case graded on a kotlinx-coroutines-test scheduler of its own through the runner's bridge cs.coroutines, which the starter's build.gradle.kts puts on the classpath with the cs.coroutines plugin: publish hands a message to receive, a suspend function that waits for one under withTimeoutOrNull; sleep returns the time it slept as the scheduler's clock measures it (its timeSource, from the coroutine context); steps chains delays and returns the time each one ended; race starts coroutines that all wake at the same instant and returns the order they woke in, the order they were scheduled (abcd); hold waits on a deferred nobody completes; fail throws after a delay; jam takes a semaphore it holds, which blocks the case's thread; leave starts a coroutine in its caller's scope that never ends. ex1, advance, spawn-join, chain and ties are visible, so their generated runTest tests run natively on the reference. limits.hang_guard_ms is 1000 pass, and its generated tests ok, but deadlock stalled at op 3 (@join r1): deadlock at 2000 ms with no restart, task-error an error at its @join (conformance failure, op 3), jam timeout and leftover stalled at op 2 (@now): the case ended with coroutines still active at 0 ms; the cases after each still run
conformance-project-stress-python reference, broken-unlocked-add A Python project with a stress case at level 2: the entry class Tally in tally/tally.py keeps its counts in tally/counts.py, whose add reads and writes a count under one lock; the broken overlay replaces tally/counts.py with an add that reads the count on one line and writes it on the next without the lock, in a file other than the entry's, where only injected yields across the project reach it. s1 runs 4 workers that add("k", 1) 500 times each, then checks that no add returned the same count twice and the final count reference passes s1 10 of 10; broken-unlocked-add passes the sequential cases and fails s1 in at least 9 of 10
conformance-project-stress-typescript reference, broken-unlocked-add A TypeScript project on the virtual clock with a stress case: add is asynchronous and reads and writes a count with no await between them; the broken overlay awaits between reading and writing. Its sequential cases run on the virtual clock (clock advances it 1000 ms), its stress case on the real clock in the async model, 4 tasks of 200 adds as for Python
conformance-project-stress-java reference, broken-unlocked-add A Java project whose entry class tally.Tally keeps its counts in tally.Counts, whose methods are synchronized; the broken overlay's add reads a count from a ConcurrentHashMap, calls Thread.yield(), then writes it, without the monitor. jvm_threads lists platform and virtual: on JDK 21 to 23 a virtual thread pins its carrier inside synchronized, from JDK 24 it does not (JEP 491); either way the reference is correct, and pinning only slows it. 4 workers of 1000 adds as for Python, per thread kind
conformance-project-stress-kotlin reference, broken-unlocked-add The Java fixture in Kotlin: tally.Counts holds a ReentrantLock (withLock), and the broken add yields between reading and writing without it as for Java
conformance-project-stress-clock-kotlin reference, broken-unlocked-add The Kotlin fixture on the virtual clock: tally.Tally's methods are suspend functions, and tally.Counts holds a coroutine Mutex (withLock); its sequential cases run on the virtual clock, and each worker thread of s1 calls add in runBlocking on the real clock, as platform and virtual threads. The broken add yields its thread between reading and writing a count, without the mutex reference passes s1 in 10 of 10 runs per thread kind; broken-unlocked-add passes the sequential cases and fails s1 in at least 9 of 10
conformance-project-stress-go reference, broken-unlocked-add A Go project on the virtual clock with a stress case: the entry type Tally keeps its counts in a map under a sync.Mutex (counts.go); the broken overlay's add reads the count under the mutex, lets it go, calls runtime.Gosched(), then writes it under the mutex again, so the race is a lost update and never a concurrent map write. Its sequential cases run in testing/synctest bubbles of the grading test binary, its stress runs outside them on the real clock as for Python
conformance-project-stress-rust reference, broken-unlocked-add A Rust crate tally whose entry class takes &self throughout, since worker threads share it from level 2: its counts sit in a Mutex<HashMap<String, i32>> in src/counts.rs; the broken overlay's add reads under the lock, drops it, calls std::thread::yield_now(), then writes under the lock again. The bridge registers the class as shared from level 2 as for Python

A project fixture lists exactly one language.