Split the 657-line operation service into eor, submit, and verify modules, add the AGENT_REVOKED and KEY_RETIRED codes the Backend already emits, and condense every multi-line comment. Mirror Node, Python, and Go at 2.1.0 with the deep-health 503, non-idempotent retry, rotation grace, and path-encoding fixes. Document which routes and response fields the self-hosted server does not provide. Claude-Session: https://claude.ai/code/session_01Agoc9bRVE9KL7mmWtey9Vq
79 lines
2.4 KiB
JavaScript
79 lines
2.4 KiB
JavaScript
import { mkdir, writeFile } from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
import { pathToFileURL } from 'node:url';
|
|
import {
|
|
createFixtureRoot,
|
|
distUrl,
|
|
homeEnvironment,
|
|
installConfig as baseInstallConfig,
|
|
runPlugin as basePlugin,
|
|
} from './harness.mjs';
|
|
|
|
export {
|
|
VALID_PRIVATE_KEY,
|
|
cliPath,
|
|
readJson,
|
|
registryModuleUrl,
|
|
runNode,
|
|
runProcess,
|
|
startApiServer,
|
|
} from './harness.mjs';
|
|
|
|
export const pluginModuleUrl = distUrl('plugins/opencode.js');
|
|
export const contractModuleUrl = distUrl('plugins/opencode-contract.js');
|
|
export const installationModuleUrl = distUrl('plugins/opencode-installation.js');
|
|
export const ioModuleUrl = distUrl('plugins/opencode-io.js');
|
|
const PLUGIN = { exportName: 'opencodePlugin', moduleUrl: pluginModuleUrl };
|
|
|
|
export function environment(fixture) {
|
|
return { ...homeEnvironment(fixture), XDG_CONFIG_HOME: fixture.configRoot };
|
|
}
|
|
|
|
export function installConfig(fixture, overrides = {}) {
|
|
return baseInstallConfig('opencode', fixture, overrides);
|
|
}
|
|
|
|
export function runPlugin(fixture, method, argument) {
|
|
return basePlugin(PLUGIN, fixture, method, argument, { env: environment(fixture) });
|
|
}
|
|
|
|
async function writeOptional(filePath, value) {
|
|
if (value === undefined) return;
|
|
await mkdir(path.dirname(filePath), { recursive: true });
|
|
await writeFile(filePath, value, { mode: 0o600 });
|
|
}
|
|
|
|
export async function createFixture({
|
|
agentId = 'agent-1',
|
|
baseUrl = 'http://127.0.0.1:9',
|
|
existingPlugin,
|
|
existingLegacy,
|
|
} = {}) {
|
|
const base = await createFixtureRoot(
|
|
'elydora-opencode-',
|
|
"home with spaces and 'quote %OPEN%",
|
|
{ agentId, projectName: 'workspace with spaces', createHome: true },
|
|
);
|
|
const configRoot = path.join(base.rootDir, 'xdg config');
|
|
const pluginsDir = path.join(configRoot, 'opencode', 'plugins');
|
|
const pluginPath = path.join(pluginsDir, 'elydora-audit.js');
|
|
const legacyPluginPath = path.join(pluginsDir, 'elydora-audit.mjs');
|
|
await writeOptional(pluginPath, existingPlugin);
|
|
await writeOptional(legacyPluginPath, existingLegacy);
|
|
return {
|
|
...base,
|
|
baseUrl,
|
|
configRoot,
|
|
legacyPluginPath,
|
|
pluginPath,
|
|
pluginsDir,
|
|
install(overrides = {}) {
|
|
return runPlugin(this, 'install', installConfig(this, overrides));
|
|
},
|
|
async loadPlugin() {
|
|
const module = await import(`${pathToFileURL(this.pluginPath).href}?test=${Date.now()}`);
|
|
return module.ElydoraAuditPlugin({});
|
|
},
|
|
};
|
|
}
|