prime
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"llm": {
|
||||
"model": "experimental-model",
|
||||
"reasoning": null,
|
||||
"nested": {
|
||||
"extra": true
|
||||
}
|
||||
},
|
||||
"run": {
|
||||
"label": "experiment",
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"llm": {
|
||||
"host": "remote-box",
|
||||
"model": "remote-model",
|
||||
"nested": {
|
||||
"replace": "remote"
|
||||
},
|
||||
"list": ["remote"]
|
||||
},
|
||||
"run": {
|
||||
"label": "remote"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"beta-demo": {
|
||||
"module": "beta",
|
||||
"builder": "buildBeta",
|
||||
"params": ["demo"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"prefix": "alpha"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"client": "lm-studio",
|
||||
"host": "localhost",
|
||||
"port": 1234,
|
||||
"model": "local-model",
|
||||
"reasoning": true,
|
||||
"nested": {
|
||||
"keep": "default",
|
||||
"replace": "default"
|
||||
},
|
||||
"list": ["default"]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"alpha": "./tree/alpha/index.js",
|
||||
"beta": "./tree/beta/index.js"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
module.exports = utils => {
|
||||
function loadAlpha(value) {
|
||||
const prefix = utils.getSettings("input").prefix;
|
||||
return utils.buildNode(`${prefix}:${value}`);
|
||||
}
|
||||
|
||||
return { loadAlpha };
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
module.exports = utils => {
|
||||
function buildBeta(value) {
|
||||
const alpha = utils.loadModule("alpha");
|
||||
const source = alpha.loadAlpha(value);
|
||||
return utils.buildNode(`beta:${source.payload}`, { alpha: source });
|
||||
}
|
||||
|
||||
return { buildBeta };
|
||||
};
|
||||
@@ -0,0 +1,84 @@
|
||||
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;
|
||||
});
|
||||
Reference in New Issue
Block a user