open-design/apps/daemon/tests/agent-runtime-env.test.ts
marco 5dd70b5016
Some checks failed
ci / Validate workspace (push) Successful in 12m32s
landing-page-ci / Validate landing page (push) Successful in 9m41s
landing-page-deploy / Deploy landing page (push) Failing after 5m23s
github-metrics / Generate repository metrics SVG (push) Failing after 2m3s
refresh-contributors-wall / Refresh contributors wall cache bust (push) Failing after 11s
Initial import: open-design source for helix-mind.ai distribution
This repository contains the open-design daemon CLI source code, built
and packaged at https://helix-mind.ai/cli/open-design/latest.tgz for use
by the HelixMind /design slash command.

Licenses: Apache-2.0 (root) + MIT (skills/*)
2026-05-06 20:50:24 +02:00

58 lines
2.2 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { createAgentRuntimeEnv, createAgentRuntimeToolPrompt } from '../src/server.js';
describe('agent runtime tool environment', () => {
it('injects daemon URL and run-scoped tool token into agent sessions', () => {
const env = createAgentRuntimeEnv(
{ PATH: '/bin', OD_TOOL_TOKEN: 'stale-token' },
'http://127.0.0.1:7456',
{ token: 'fresh-token' },
'/opt/open-design/bin/node',
);
expect(env).toMatchObject({
PATH: '/bin',
OD_DAEMON_URL: 'http://127.0.0.1:7456',
OD_NODE_BIN: '/opt/open-design/bin/node',
OD_TOOL_TOKEN: 'fresh-token',
});
});
it('does not leak stale inherited tool tokens when no run token was minted', () => {
const env = createAgentRuntimeEnv(
{ PATH: '/bin', OD_TOOL_TOKEN: 'stale-token' },
'http://127.0.0.1:7456',
null,
'/opt/open-design/bin/node',
);
expect(env.OD_DAEMON_URL).toBe('http://127.0.0.1:7456');
expect(env.OD_NODE_BIN).toBe('/opt/open-design/bin/node');
expect(env.OD_TOOL_TOKEN).toBeUndefined();
});
it('describes daemon URL and token availability without exposing the token', () => {
const prompt = createAgentRuntimeToolPrompt('http://127.0.0.1:7456', {
token: 'secret-run-token',
});
expect(prompt).toContain('Daemon URL: `http://127.0.0.1:7456`');
expect(prompt).toContain('`OD_DAEMON_URL`');
expect(prompt).toContain('`OD_NODE_BIN`');
expect(prompt).toContain('`"$OD_NODE_BIN" "$OD_BIN" tools ...`');
expect(prompt).toContain('& $env:OD_NODE_BIN $env:OD_BIN tools ...');
expect(prompt).toContain('`OD_TOOL_TOKEN` is available');
expect(prompt).toContain('do not print, persist, or override it');
expect(prompt).not.toContain('secret-run-token');
});
it('describes missing token availability without exposing stale internals', () => {
const prompt = createAgentRuntimeToolPrompt('http://127.0.0.1:7456', null);
expect(prompt).toContain('Daemon URL: `http://127.0.0.1:7456`');
expect(prompt).toContain('`OD_TOOL_TOKEN` is not available');
expect(prompt).not.toContain('Bearer');
});
});