This commit is contained in:
felix
2026-09-14 13:57:42 +02:00
commit 4ef33c6417
951 changed files with 155793 additions and 0 deletions

8
dev-stubs/mu-hooks.mjs Normal file
View File

@@ -0,0 +1,8 @@
// Maps the 'mu' import to dev-stubs/mu-stub.mjs, so tests run without the
// template container.
export async function resolve(specifier, context, nextResolve) {
if (specifier === 'mu') {
return { shortCircuit: true, url: new URL('./mu-stub.mjs', import.meta.url).href };
}
return nextResolve(specifier, context);
}

33
dev-stubs/mu-stub.mjs Normal file
View File

@@ -0,0 +1,33 @@
// Byte-for-byte copies of the three mu helpers the chat store uses, so the
// unit test asserts on the same strings the container produces.
// Registered for the 'mu' module by dev-stubs/register.js during tests only.
export function sparqlEscapeString(value) {
return '"""' + value.replace(/[\\"]/g, (m) => '\\' + m) + '"""';
}
// The loop test drives ask() end to end; describe/lookup tools reach the
// session helpers, so the stub implements them as no-ops.
export async function query() {
return { results: { bindings: [] }, head: { vars: [] } };
}
export async function update() {}
export function sparqlEscapeUri(value) {
return '<' + value.replace(/[\\"<>]/g, function (match) { return '\\' + match; }) + '>';
}
export function sparqlEscapeDateTime(value) {
return '"' + new Date(value).toISOString() + '"^^xsd:dateTime';
}
// The remaining template helpers db.js imports, copied from
// helpers/mu/sparql.js in mu-javascript-template.
export function sparqlEscapeInt(value) {
return '"' + Number.parseInt(value) + '"^^xsd:integer';
}
export function sparqlEscapeDate(value) {
return '"' + new Date(value).toISOString().substring(0, 10) + '"^^xsd:date';
}
export function sparqlEscapeBool(value) {
return value ? '"true"^^xsd:boolean' : '"false"^^xsd:boolean';
}

5
dev-stubs/register.js Normal file
View File

@@ -0,0 +1,5 @@
// node --import ./dev-stubs/register.js <test file>
// Registers the 'mu' resolve hook (mu-hooks.mjs -> mu-stub.mjs).
import { register } from 'node:module';
register(new URL('./mu-hooks.mjs', import.meta.url).href);