Files
openworker/deploy/service/local-values.test.mjs
Rohit PrasadandDevika Verma d53e058eda Introduce OpenWorker Harness SDK (in beta), agent service cluster and relevant developer documentation (#844)
Allow developers to easily build AI apps without worrying about the harness part.
Bundles the Rust agent runtime as a SDK (Rust and TypeScript) for building desktop and web applications. Applications can manage a local harness or connect to an authenticated harness service on k8s with separately scaled workers and sandbox execution.

The implementation is primarily contained in harness/, with deployment tooling in deploy/, Markdown guides in docs/harness/guides/, and the static documentation site in docs-site/. It does not replace the existing Python harness or migrate OpenWorker Desktop.

Co-authored-by: Devika Verma <devikaverma11@gmail.com>
2026-11-06 09:45:20 -08:00

107 lines
4.1 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { mkdtemp, writeFile, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { localValues } from "./local-values.mjs";
import { run, serviceConfig } from "./stack.mjs";
const runtime = {
imageRef: "example/service@sha256:" + "a".repeat(64),
runnerImage: "example/runner@sha256:" + "b".repeat(64),
};
test("local live-model values mount only a worker secret reference; scripted profiles do not", () => {
const input = {
scripted: false,
model_provider: "anthropic",
openshell: { image: "replace" },
model_connections: [
{
id: "primary",
provider: "anthropic",
identity: "test",
key_env: "ANTHROPIC_API_KEY",
},
],
};
const live = localValues(input, runtime);
assert.equal(live.secrets.model, "ow-service-model");
assert.equal(input.openshell.image, "replace");
assert.equal(live.config.openshell.image, runtime.runnerImage);
assert.equal(live.config.runner, "/opt/openworker/openworker");
assert.equal(
localValues({ ...input, scripted: true }, runtime).secrets.model,
"",
);
});
test("rendered live local profile mounts model data only into the worker", async () => {
const values = localValues(
{
service: {
id: "test-service",
namespace: "test",
agent: "installed-tools",
},
scripted: false,
model_provider: "anthropic",
openshell: { image: "replace" },
model_connections: [
{
id: "primary",
provider: "anthropic",
identity: "test",
key_env: "ANTHROPIC_API_KEY",
},
],
},
runtime,
);
const dir = await mkdtemp(join(tmpdir(), "ows-live-model-"));
try {
const path = join(dir, "values.json");
await writeFile(path, JSON.stringify(values));
const out = await run("helm", [
"template",
"test",
resolve("deploy/service/chart"),
"-f",
path,
]);
const docs = out.split("\n---");
const worker = docs.find(
(x) => x.includes("kind: Deployment") && x.includes("name: test-worker"),
);
assert.match(worker, /mountPath: \/models, readOnly: true/);
assert.match(worker, /secretName: ow-service-model/);
for (const role of ["api", "controller", "platform"]) {
const doc = docs.find(
(x) =>
x.includes("kind: Deployment") && x.includes(`name: test-${role}`),
);
assert.doesNotMatch(doc, /mountPath: \/models/);
}
assert.doesNotMatch(out, /sk-ant-|modelKeyFile/);
} finally {
await rm(dir, { recursive: true, force: true });
}
});
test("local initialization retains explicit recording configuration without enabling it by default", () => {
const base = {scripted:true,openshell:{endpoint:"https://gateway.example:8080",image:"runner@sha256:"+"c".repeat(64)}};
assert.equal(serviceConfig(base,"ows-test").observability,undefined);
const observability = {schema:"ow_observability",queue_capacity:1024,retention_days:7};
const c=serviceConfig({...base,observability},"ows-test");
assert.deepEqual(c.observability,observability);
c.observability.retention_days=30;
assert.equal(observability.retention_days,7);
});
test("local initialization preserves operator Git grants without implicitly selecting one",()=>{
const base={scripted:true,openshell:{endpoint:"https://gateway.example:8080",image:"runner@sha256:"+"c".repeat(64)}};
assert.equal(serviceConfig(base,"ows-test").openshell.git_grants,undefined);
const grant={provider:{name:"github",provider_id:"original",profile_id:"github",profile_workspace:"",profile_digest:"a".repeat(64)},scope:{host:"github.com",repositories:["org/repo"]}};
const c=serviceConfig({...base,openshell:{...base.openshell,git_grants:{"github@1":grant}}},"ows-test");
assert.deepEqual(c.openshell.git_grants,{"github@1":grant});
assert.equal(c.openshell.selected_git_grant,undefined);
c.openshell.git_grants["github@1"].scope.repositories.push("changed/repo");
assert.deepEqual(grant.scope.repositories,["org/repo"]);
});