Send Compile & run through a CompileBackend instead of straight to godbolt
Every compile went to godbolt.org from the session directly. The roadmap moves compiles, and later Dafny and Lean checks, to a pinned service of the app's own, and godbolt has no service guarantee, so where a compile goes is now one replaceable piece. - src/services/compile-backend.ts: a CompileBackend (id, host, compiler, compile), explorerBackend() for any service that speaks Compiler Explorer's API at a base URL, GODBOLT as the default, and compileBackend() / setCompileBackend(). - godbolt.ts: compileMojo takes a CompileTarget (base, compiler, host) and names that host in its messages; the request body is unchanged, so tests/mojo.test.mjs still holds it to what the corpus pipeline sends. - Session.compile asks the current backend and records which host answered (CompileRecord.host; older records came from godbolt.org). - The Compiler view names the host it is asking and the host that answered. The "Compiled on godbolt" badge keeps its wording until a second backend is deployed. A test sends a compile through a fake backend and a refused local address. Manual check list: open a Mojo exercise in the Developer area, Compile & run, and see "Asking godbolt.org (mojo_1_1_0)…" then "Mojo 1.1.0 on godbolt.org" in the Compiler view. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FgvbRdoEheAHqsRmr2WuKZ
This commit is contained in:
5 files changed
+91
-15
No files matched your search
@@ -213,6 +213,32 @@ test('the session keeps each answer with the source it answered, and says when i
|
||||
assert.equal(failed.outcome.error, 'Could not reach godbolt.org (offline).');
|
||||
});
|
||||
|
||||
test('Compile & run goes through the compile backend, and the record names the service that answered', async () => {
|
||||
const { compileBackend, setCompileBackend, explorerBackend, GODBOLT } = await import('../dist/services/compile-backend.js');
|
||||
assert.equal(compileBackend(), GODBOLT);
|
||||
assert.equal(GODBOLT.host, 'godbolt.org');
|
||||
assert.equal(GODBOLT.compiler, 'mojo_1_1_0');
|
||||
const asked = [];
|
||||
const fake = { id: 'fake', host: 'checker.example', compiler: 'mojo_1_1_0', compile: async (source, opts) => { asked.push({ source, ...opts }); return { answer: null, error: 'checker.example did not answer in time.', seconds: 0 }; } };
|
||||
const prev = setCompileBackend(fake);
|
||||
try {
|
||||
const s = new Session(normalize({ v: 3, lang: 'mojo', sources: { mojo: 'def main():\n print(7)\n' } }));
|
||||
const rec = await s.compile();
|
||||
assert.equal(asked.length, 1);
|
||||
assert.equal(asked[0].source, 'def main():\n print(7)\n');
|
||||
assert.equal(asked[0].level, 'O0');
|
||||
assert.equal(rec.host, 'checker.example');
|
||||
} finally {
|
||||
setCompileBackend(prev);
|
||||
}
|
||||
assert.equal(compileBackend(), GODBOLT);
|
||||
// a Compiler Explorer at another address speaks the same API and names itself in its messages
|
||||
const elsewhere = explorerBackend('local', { base: 'http://127.0.0.1:9', compiler: 'mojo_1_1_0', host: 'the local checker' });
|
||||
const out = await elsewhere.compile('def main():\n pass\n', { timeoutMs: 2000 });
|
||||
assert.equal(out.answer, null);
|
||||
assert.match(out.error, /the local checker/);
|
||||
});
|
||||
|
||||
test('godbolt\'s answer outlives the session: a new one for the same source finds it without asking again', async () => {
|
||||
const { forgetCompiles } = await import('../dist/core/compiles.js');
|
||||
forgetCompiles();
|
||||
|
||||
Reference in new issue
Block a user