HS: mixed-op enforcement + short-circuit + typecheck + strings (+7 tests)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 10m43s

- parser.sx: parse-logical now rejects mixed and/or without parens
- parser.sx: parse-arith now rejects mixed +/-/* //%/mod without parens
- generate-sx-tests.py: MANUAL_TEST_BODIES for short-circuit and/or,
  typecheck (direct hs-type-assert calls), template string test
- generate-sx-tests.py: Pattern 5 for error("expr") -> assert-throws
- hs-run-filtered.js: redefine try-call to _run-test-thunk after loading
  so assert-throws actually catches exceptions (was always {ok true})
- hs-run-filtered.js: clear __hs_deadline immediately after test eval
  to prevent cascading timeout fires in result inspection K.eval calls
- hs-run-filtered.js: typecheck suite in _NO_STEP_LIMIT_SUITES and
  _SLOW_DEADLINE_SUITES (hs-type-assert JIT is slow on first call)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-04 11:31:56 +00:00
parent 894fd24c3a
commit 51bc075da5
5 changed files with 240 additions and 43 deletions

View File

@@ -740,6 +740,11 @@ for(const f of['spec/harness.sx','spec/tests/test-framework.sx','spec/tests/test
}
process.stderr.write(`Tests loaded in ${Date.now()-t_tests}ms\n`);
// Redefine try-call to actually catch errors for assert-throws.
// During loading it was the registration version (stores thunks, returns {:ok true}).
// Now that tests are registered, redefine it to run the thunk and catch any exception.
K.eval('(define try-call _run-test-thunk)');
// Override eval-hs-error for runtimeErrors tests: hs-null-raise!/hs-empty-raise!/hs-win-call
// each wrap their (raise msg) in a self-contained guard so the raise is swallowed before
// it can escape through the empty JIT kont and trigger the slow host_error path (~34s).
@@ -806,6 +811,7 @@ for(let i=startTest;i<Math.min(endTest,testCount);i++){
const _NO_STEP_LIMIT_SUITES = new Set([
"hs-upstream-core/runtimeErrors",
"hs-upstream-expressions/collectionExpressions",
"hs-upstream-expressions/typecheck",
]);
// Enable step limit for timeout protection — reset counter first so accumulation
// across tests doesn't cause signed-32-bit wraparound (~2B extra steps before limit fires).
@@ -820,6 +826,7 @@ for(let i=startTest;i<Math.min(endTest,testCount);i++){
const _SLOW_DEADLINE_SUITES = {
"hs-upstream-core/runtimeErrors": 30000,
"hs-upstream-expressions/collectionExpressions": 60000,
"hs-upstream-expressions/typecheck": 30000,
};
_testDeadline = Date.now() + (_SLOW_DEADLINE[name] || _SLOW_DEADLINE_SUITES[suite] || 10000);
globalThis.__hs_deadline = _testDeadline; // expose to WASM cek_step_loop
@@ -828,13 +835,23 @@ for(let i=startTest;i<Math.min(endTest,testCount);i++){
let ok=false,err=null;
try{
// Use SX-level guard to catch errors, avoiding __sxR side-channel issues
// Returns a dict with :ok and :error keys
K.eval(`(define _test-result (_run-test-thunk (get (nth _test-registry ${i}) "thunk")))`);
const isOk=K.eval('(get _test-result "ok")');
if(isOk===true){ok=true;}
else{
const errMsg=K.eval('(get _test-result "error")');
err=errMsg?String(errMsg).slice(0,150):'unknown error';
// Returns a dict with :ok and :error keys.
// Note: api_eval returns "Error: <msg>" string (not throw) for SX exceptions,
// so K.eval may return an error string rather than throwing. Check for this.
const defineR = K.eval(`(define _test-result (_run-test-thunk (get (nth _test-registry ${i}) "thunk")))`);
// Clear deadline immediately: once the test thunk finishes (or times out and
// the guard catches it), further K.eval calls for result inspection must not
// keep re-firing the deadline check on every 10k steps.
globalThis.__hs_deadline = 0;
if(typeof defineR==='string' && defineR.startsWith('Error: ')){
err=defineR.slice(7,157); // strip "Error: " prefix
} else {
const isOk=K.eval('(get _test-result "ok")');
if(isOk===true){ok=true;}
else{
const errMsg=K.eval('(get _test-result "error")');
err=errMsg?String(errMsg).slice(0,150):'unknown error';
}
}
}catch(e){err=(e.message||'').slice(0,150);}
setStepLimit(0); // disable step limit between tests