85 lines
3.4 KiB
JavaScript
85 lines
3.4 KiB
JavaScript
const assert = require("assert");
|
|
const crypto = require("crypto");
|
|
const fs = require("fs");
|
|
const os = require("os");
|
|
const path = require("path");
|
|
const { initialize, hashPayload, buildNode, buildBinaryNode } = require("..");
|
|
|
|
async function main() {
|
|
const projectRoot = path.join(__dirname, "fixture");
|
|
const optimus = initialize(projectRoot);
|
|
|
|
assert.deepStrictEqual(optimus.modules, ["alpha", "beta"]);
|
|
assert.strictEqual(optimus.getSettings("input").prefix, "alpha");
|
|
assert.strictEqual(optimus.loadModule("alpha").loadAlpha("x").payload, "alpha:x");
|
|
assert.throws(() => optimus.loadModule("missing"), /Unknown module/);
|
|
assert.throws(() => optimus.getSettings("missing"), /Unknown settings/);
|
|
|
|
const overlaid = initialize(projectRoot, {
|
|
settingOverlays: ["overlays/remote.json", "overlays/experiment.json"],
|
|
});
|
|
assert.deepStrictEqual(overlaid.getSettings("llm"), {
|
|
client: "lm-studio",
|
|
host: "remote-box",
|
|
port: 1234,
|
|
model: "experimental-model",
|
|
reasoning: null,
|
|
nested: {
|
|
keep: "default",
|
|
replace: "remote",
|
|
extra: true,
|
|
},
|
|
list: ["remote"],
|
|
});
|
|
assert.deepStrictEqual(overlaid.getSettings("run"), { label: "experiment", enabled: true });
|
|
|
|
const expectedHash = crypto.createHash("sha256").update(JSON.stringify({ a: 1 })).digest("hex");
|
|
assert.strictEqual(hashPayload({ a: 1 }), expectedHash);
|
|
|
|
const source = buildNode({ source: true });
|
|
const node = buildNode({ result: true }, { source });
|
|
assert.deepStrictEqual(node.sourceHash, { source: source.hash });
|
|
assert.strictEqual(node.hash, hashPayload(node.payload));
|
|
assert.deepStrictEqual(node.payload, { result: true });
|
|
|
|
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "optimus-binary-"));
|
|
const binaryPath = path.join(tempRoot, "sample.bin");
|
|
const firstBytes = Buffer.from([0x00, 0x01, 0x02, 0xff]);
|
|
const secondBytes = Buffer.from([0x00, 0x01, 0x03, 0xff]);
|
|
|
|
try {
|
|
fs.writeFileSync(binaryPath, firstBytes);
|
|
const binaryNode = buildBinaryNode(binaryPath, { source });
|
|
const expectedBinaryHash = crypto.createHash("sha256").update(firstBytes).digest("hex");
|
|
assert.deepStrictEqual(binaryNode.sourceHash, { source: source.hash });
|
|
assert.strictEqual(binaryNode.hash, expectedBinaryHash);
|
|
assert.strictEqual(binaryNode.payloadBin, binaryPath);
|
|
assert.strictEqual("payload" in binaryNode, false);
|
|
|
|
const binaryViaUtils = optimus.utils.buildBinaryNode(binaryPath);
|
|
assert.strictEqual(binaryViaUtils.hash, expectedBinaryHash);
|
|
|
|
fs.writeFileSync(binaryPath, secondBytes);
|
|
const changedBinaryNode = buildBinaryNode(binaryPath);
|
|
assert.notStrictEqual(changedBinaryNode.hash, binaryNode.hash);
|
|
assert.strictEqual(changedBinaryNode.payloadBin, binaryPath);
|
|
} finally {
|
|
fs.rmSync(tempRoot, { recursive: true, force: true });
|
|
}
|
|
|
|
const artifact = optimus.buildArtifact("beta-demo");
|
|
assert.strictEqual(typeof artifact?.then, "undefined");
|
|
assert.deepStrictEqual(artifact.sourceHash, { alpha: optimus.loadModule("alpha").loadAlpha("demo").hash });
|
|
assert.strictEqual(artifact.payload, "beta:alpha:demo");
|
|
|
|
const all = await optimus.buildAll();
|
|
assert.strictEqual(all, undefined);
|
|
|
|
console.log("smoke test passed");
|
|
}
|
|
|
|
main().catch(error => {
|
|
console.error(error);
|
|
process.exitCode = 1;
|
|
});
|