nanocoai/nanoclaw / .claude/skills/add-iron-proxy
add-iron-proxy
FlaggedInstall or refresh Iron Proxy and its official Iron Control web console for NanoClaw. Use when selecting the Iron gateway, adding its management UI, configuring credentials and grants, or restoring the proxy, approval bridge, and agent guidance.
scripts/auth-resume.test.ts
View on GitHubimport fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import http from 'node:http';
import { afterEach, expect, it, vi } from 'vitest';
import * as prompts from '@clack/prompts';
import { run } from './auth.js';
import { controlPaths } from './control.js';
vi.mock('@clack/prompts', () => ({
isCancel: () => false,
select: vi.fn(async () => 'oauth'),
password: vi.fn(async () => 'sk-ant-oat-fixture'),
log: { success: vi.fn(), warn: vi.fn() },
}));
let cleanup: (() => Promise<void>) | undefined;
afterEach(async () => {
await cleanup?.();
cleanup = undefined;
vi.clearAllMocks();
vi.unstubAllEnvs();
});
async function fixture() {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'iron-auth-resume-'));
let credential: any;
let granted = false;
let unavailable = false;
let failGrant = false;
let storedSecret: string | undefined;
const server = http.createServer(async (req, res) => {
const chunks: Buffer[] = [];
for await (const chunk of req) chunks.push(Buffer.from(chunk));
const resource = req.url;
let data: unknown;
if (unavailable) {
res.writeHead(503);
res.end();
return;
}
if (resource === '/api/v1/static_secrets/nanoclaw-model' && req.method === 'PUT') {
const value = JSON.parse(Buffer.concat(chunks).toString()).data;
storedSecret = value.source?.secret;
credential = { ...value, id: 'model-id', foreign_id: 'nanoclaw-model', source: undefined };
data = credential;
} else if (resource?.startsWith('/api/v1/static_secrets/lookup/') && resource.endsWith('/nanoclaw-model')) {
if (!credential) {
res.writeHead(404);
res.end();
return;
}
data = credential;
} else if (resource === '/api/v1/principals/principal/roles') data = [];
else if (resource === '/api/v1/static_secrets/model-id') data = credential;
else if (resource?.startsWith('/api/v1/principals/principal/grants'))
data = granted ? [{ static_secret_id: 'model-id' }] : [];
else if (resource === '/api/v1/grants') {
if (failGrant) {
failGrant = false;
res.writeHead(503);
res.end();
return;
}
granted = true;
data = { id: 'grant-id' };
} else {
res.writeHead(404);
res.end();
return;
}
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({ data }));
});
await new Promise<void>((resolve, reject) => {
server.once('error', (error) => {
fs.rmSync(root, { recursive: true, force: true });
reject(error);
});
server.listen(0, '127.0.0.1', resolve);
});
const port = (server.address() as { port: number }).port;
const paths = controlPaths(root);
fs.mkdirSync(paths.directory, { recursive: true });
fs.writeFileSync(paths.environment, 'IRON_CONTROL_INITIAL_API_KEY=fixture-only\n', { mode: 0o600 });
fs.writeFileSync(paths.registration, JSON.stringify({ principalId: 'principal', proxyId: 'proxy' }));
fs.writeFileSync(
path.join(root, '.env'),
`NANOCLAW_IRON_CONTROL_PORT=${port}\nNANOCLAW_IRON_CONTROL_URL=http://127.0.0.1:${port}\n`,
);
for (const key of [
'NANOCLAW_ANTHROPIC_API_KEY',
'ANTHROPIC_API_KEY',
'NANOCLAW_ANTHROPIC_BASE_URL',
'NANOCLAW_ANTHROPIC_AUTH_TOKEN',
'NANOCLAW_IRON_CONTROL_PORT',
])
vi.stubEnv(key, '');
cleanup = async () => {
await new Promise<void>((resolve, reject) => server.close((err) => (err ? reject(err) : resolve())));
fs.rmSync(root, { recursive: true, force: true });
};
return {
root,
failNextGrant() {
failGrant = true;
},
outage() {
unavailable = true;
},
storedSecret() {
return storedSecret;
},
};
}
it('resumes a managed OAuth login after an interrupted grant without repeating authorization', async () => {
const control = await fixture();
control.failNextGrant();
await expect(run('claude', control.root)).rejects.toThrow('503');
for (let retry = 0; retry < 3; retry++) await run('claude', control.root);
expect(prompts.select).toHaveBeenCalledTimes(1);
expect(prompts.password).toHaveBeenCalledTimes(1);
expect(fs.readFileSync(path.join(control.root, '.env'), 'utf8')).toContain(
'NANOCLAW_IRON_PROXY_AUTH_ENV=CLAUDE_CODE_OAUTH_TOKEN',
);
expect(fs.existsSync(path.join(control.root, 'data/session-materials/iron-proxy/shared/upstream-secret'))).toBe(
false,
);
});
it('reports a control outage instead of asking a connected user to sign in again', async () => {
const control = await fixture();
await run('claude', control.root);
control.outage();
await expect(run('claude', control.root)).rejects.toThrow('503');
expect(prompts.select).toHaveBeenCalledTimes(1);
});
it('stores a pasted service-account API key, and the API-key prompt accepts every API key type', async () => {
const control = await fixture();
vi.mocked(prompts.select).mockResolvedValueOnce('api');
vi.mocked(prompts.password).mockResolvedValueOnce(' sk-ant-svc01-\nfixture ');
await run('claude', control.root);
expect(control.storedSecret()).toBe('sk-ant-svc01-fixture');
expect(fs.readFileSync(path.join(control.root, '.env'), 'utf8')).toContain(
'NANOCLAW_IRON_PROXY_AUTH_ENV=ANTHROPIC_API_KEY',
);
const { message, validate } = vi.mocked(prompts.password).mock.calls[0][0];
expect(message).toMatch(/one workspace/);
for (const key of ['sk-ant-api03-x', 'sk-ant-usr01-x', 'sk-ant-svc01-x']) expect(validate?.(key)).toBeUndefined();
});
it('stores an OAuth token pasted into the API-key prompt as an OAuth token', async () => {
const control = await fixture();
vi.mocked(prompts.select).mockResolvedValueOnce('api');
vi.mocked(prompts.password).mockResolvedValueOnce(' sk-ant-oat01-\nfixture ');
await run('claude', control.root);
expect(control.storedSecret()).toBe('sk-ant-oat01-fixture');
expect(fs.readFileSync(path.join(control.root, '.env'), 'utf8')).toContain(
'NANOCLAW_IRON_PROXY_AUTH_ENV=CLAUDE_CODE_OAUTH_TOKEN',
);
});
it('rejects an API key in the OAuth-token prompt', async () => {
const control = await fixture();
await run('claude', control.root);
const { validate } = vi.mocked(prompts.password).mock.calls[0][0];
expect(validate?.('sk-ant-oat01-x')).toBeUndefined();
expect(validate?.('sk-ant-svc01-x')).toMatch(/sk-ant-oat/);
});
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |