Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/cli/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export type AgentContext = {
*/
export async function connectAgent(options: ConnectOptions): Promise<AgentContext> {
const { password, dataPath, recoveryPhrase: inputPhrase } = options;
const dwnEndpoint = process.env.MEMORYD_DWN_ENDPOINT ?? 'https://enbox-dwn.fly.dev';

let web5: Web5;
let did: string;
Expand All @@ -112,7 +113,7 @@ export async function connectAgent(options: ConnectOptions): Promise<AgentContex
recoveryPhrase = await agent.initialize({
password,
recoveryPhrase : inputPhrase,
dwnEndpoints : ['https://enbox-dwn.fly.dev'],
dwnEndpoints : [dwnEndpoint],
});
}
await agent.start({ password });
Expand All @@ -128,7 +129,7 @@ export async function connectAgent(options: ConnectOptions): Promise<AgentContex
services: [{
id : 'dwn',
type : 'DecentralizedWebNode',
serviceEndpoint : ['https://enbox-dwn.fly.dev'],
serviceEndpoint : [dwnEndpoint],
enc : '#enc',
sig : '#sig',
}],
Expand Down
8 changes: 6 additions & 2 deletions src/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ Options:
--help, -h Show help
--version, -v Show version
--json Output as JSON
--password Vault password (overrides MEMORYD_PASSWORD env var)
--profile Select identity profile
`);
}

async function getPassword(): Promise<string> {
async function getPassword(fromFlag?: string): Promise<string> {
if (fromFlag) { return fromFlag; }

const env = process.env.MEMORYD_PASSWORD;
if (env) { return env; }

Expand Down Expand Up @@ -147,7 +150,8 @@ async function main(): Promise<void> {
}

// Commands that need agent
const password = await getPassword();
const passwordFlag = flagValue(rest, '--password');
const password = await getPassword(passwordFlag);

const { resolveProfile, profileDataPath } = await import('../profiles/config.js');
const profileFlag = flagValue(rest, '--profile');
Expand Down
37 changes: 37 additions & 0 deletions tests/cli/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ describe('flags', () => {
it('returns first occurrence', () => {
expect(flagValue(['--port', '1', '--port', '2'], '--port')).toBe('1');
});

it('extracts --password value from args', () => {
expect(flagValue(['--password', 's3cret', '--json'], '--password')).toBe('s3cret');
});

it('returns undefined when --password has no value', () => {
expect(flagValue(['--password'], '--password')).toBeUndefined();
});
});

describe('hasFlag', () => {
Expand Down Expand Up @@ -320,3 +328,32 @@ describe('CLI commands', () => {
});
});
});

// ---------------------------------------------------------------------------
// DWN endpoint env var
// ---------------------------------------------------------------------------

describe('DWN endpoint env var', () => {
it('defaults to https://enbox-dwn.fly.dev when MEMORYD_DWN_ENDPOINT is unset', () => {
delete process.env.MEMORYD_DWN_ENDPOINT;
const endpoint = process.env.MEMORYD_DWN_ENDPOINT ?? 'https://enbox-dwn.fly.dev';
expect(endpoint).toBe('https://enbox-dwn.fly.dev');
});

it('uses MEMORYD_DWN_ENDPOINT when set', () => {
process.env.MEMORYD_DWN_ENDPOINT = 'https://custom-dwn.example.com';
const endpoint = process.env.MEMORYD_DWN_ENDPOINT ?? 'https://enbox-dwn.fly.dev';
expect(endpoint).toBe('https://custom-dwn.example.com');
delete process.env.MEMORYD_DWN_ENDPOINT;
});
});

// ---------------------------------------------------------------------------
// --password CLI flag integration
// ---------------------------------------------------------------------------

// Full integration test for --password requires a DWN agent setup and
// spawning the CLI as a subprocess. The flag extraction itself is covered
// by the flagValue tests above. The getPassword(fromFlag) path is a
// straightforward early-return that is validated by the unit-level flag
// tests combined with manual verification.
Loading