Files
ruvnet__ruflo/v3/@claude-flow/cli/__tests__/proxy-console-guidance.test.ts
Dragan Spiridonov d3e647a5dd fix(proxy): bump pinned meta-proxy release 0.4.0 -> 0.7.3 (#2925)
* fix(proxy): bump pinned meta-proxy release 0.4.0 -> 0.7.3

`DEFAULT_PROXY_RELEASE` had not moved in six meta-proxy releases, so
`ruflo proxy install` shipped a binary predating every fix since v0.4.0:

  - require explicit Cognitum Cloud routing consent (#60)  first in v0.7.0
  - handle --help before binding (#74/#76)                 first in v0.7.2
  - --help/--version win from any argv position (#85)       first in v0.7.3
  - reload live daemon config on login/logout (#28)         first in v0.4.1
  - pin the Linux glibc floor to 2.28 (#66)                 first in v0.7.1

The consent one matters most: the install disclosure promises cloud
routing is "never enabled by install alone", but the commit that
separated authentication from routing consent landed in v0.7.0 — after
the pinned build.

The --version regression is directly observable on 0.4.0: the binary
starts the daemon, writes the token file and binds 127.0.0.1:11435,
where meta-proxy's own source documents --version as side-effect-free
("no server, no I/O"). Any probe silently leaves a listener running.

Also stop hardcoding the version in proxy.ts's example text. That string
was written as a literal rather than interpolating the constant, so the
advertised version could — and did — drift from the installed one. Both
tests now read the pin from the module for the same reason; asserting a
literal means every bump needs hand-edited test expectations.

Verified on Windows x64: `ruflo proxy install --release 0.7.3 --yes`
installs with signature + checksum verification intact, and `--version`
then prints and exits with no process left running and no port bound.

Test: 9 proxy test files, 56 tests, all passing.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(proxy): surface pin drift to already-installed users

Bumping DEFAULT_PROXY_RELEASE only changed what a NEW install receives.
Someone who had already run `proxy install` on 0.4.0 got no signal that
anything moved: `proxy status` reported installation as a boolean, and
`proxy update` required an explicit --release, so reaching a newer binary
meant already knowing its version number. The fixes that motivated the bump
therefore reached only the users who did not yet have the problem.

ProxyStatus now carries `version`, read from the install manifest install.ts
already writes. `proxy status` prints it, the console guidance names the gap
and the command that closes it, and `proxy update` defaults to the pin the
same way `install` does. Updating stays explicit and user-initiated.

The version is read from the manifest, never by executing the binary:
releases before v0.7.2 start the server and bind a port on ANY invocation,
so a `--version` probe against an old build leaves a listener running --
precisely the state this check exists to detect. A missing or malformed
manifest reports "unknown", never "up to date".

Also corrects two stale claims this change makes load-bearing:

  - proxy/lifecycle.ts's header asserted as fact that the binary "takes no
    CLI flags -- no --version/--help, any invocation just starts the server"
    (confirmed 2026-07-16). v0.7.2 handles --help before binding and v0.7.3
    makes --help/--version win from any argv position. Left as-is, the next
    reader concludes no version handshake is possible.

  - ADR-307 still described the pin as v0.4.0 -- a fourth copy of the literal
    this PR is de-duplicating, and the one a reviewer reads to decide what
    the pin should be. It now names no version at all and points at the
    constant, plus records the drift-surfacing behavior.

Test: 9 proxy test files, 64 tests, all passing (was 56).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-11 12:22:55 -04:00

163 lines
6.4 KiB
TypeScript

/** Bare `ruflo proxy` should be an actionable lifecycle dashboard, not the
* unrelated sponsored-capacity status command. */
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
const writeln = vi.fn();
vi.mock('../src/output.js', () => ({
output: {
writeln,
printJson: vi.fn(),
printInfo: vi.fn(),
printSuccess: vi.fn(),
printError: vi.fn(),
printWarning: vi.fn(),
createSpinner: vi.fn(),
},
}));
let stateDir: string;
let savedEnv: NodeJS.ProcessEnv;
beforeEach(() => {
stateDir = fs.mkdtempSync(path.join(os.tmpdir(), 'proxy-console-guidance-test-'));
savedEnv = { ...process.env };
process.env.RUFLO_STATE_DIR = stateDir;
writeln.mockClear();
});
afterEach(() => {
process.env = savedEnv;
fs.rmSync(stateDir, { recursive: true, force: true });
});
function renderedLines(): string[] {
return writeln.mock.calls.map(([line]) => String(line));
}
describe('bare proxy console guidance', () => {
it('tells a user with an installed but stopped proxy exactly how to start it', async () => {
const { proxyBinaryPath } = await import('../src/proxy/paths.js');
fs.mkdirSync(path.dirname(proxyBinaryPath()), { recursive: true });
fs.writeFileSync(proxyBinaryPath(), 'test binary marker');
const { proxyCommand } = await import('../src/commands/proxy.js');
const result = await proxyCommand.action!({ args: [], flags: { _: [] }, cwd: stateDir, interactive: false });
const lines = renderedLines().join('\n');
expect(result).toMatchObject({ success: true, data: { installed: true, running: false } });
expect(lines).toContain('Meta Proxy');
expect(lines).toContain('npx ruflo@latest proxy start --service');
expect(lines).toContain('npx ruflo@latest auth login');
expect(lines).not.toContain('Sponsored downtime consent');
expect(lines).not.toContain('Rate-limit flag');
});
it('gives installation guidance before the proxy exists', async () => {
const { proxyConsoleGuidance, DEFAULT_PROXY_RELEASE } = await import('../src/commands/proxy-lifecycle.js');
const lines = proxyConsoleGuidance({
installed: false,
running: false,
pid: null,
stalePidFile: false,
version: null,
}).join('\n');
expect(lines).toContain('npx ruflo@latest proxy install --yes');
// Assert against the constant, not a literal — a hardcoded version here
// would have to be edited on every pin bump, which is how the advertised
// version drifted from the installed one in the first place.
expect(lines).toContain(`Meta-Proxy v${DEFAULT_PROXY_RELEASE}`);
expect(lines).not.toContain('auth login');
});
});
/**
* A pin bump is only worth making if it reaches people who already installed
* the old one. Their entry point is this guidance, so the drift signal is
* asserted here rather than left to manual inspection.
*/
describe('pin-drift guidance for an existing install', () => {
const installedAt = (version: string | null) => ({
installed: true,
running: false,
pid: null,
stalePidFile: false,
version,
});
it('names the installed release, the pin, and the command that closes the gap', async () => {
const { proxyUpdateGuidance, DEFAULT_PROXY_RELEASE } = await import('../src/commands/proxy-lifecycle.js');
const lines = proxyUpdateGuidance(installedAt('0.4.0')).join('\n');
expect(lines).toContain('installed v0.4.0');
expect(lines).toContain(`current pin v${DEFAULT_PROXY_RELEASE}`);
expect(lines).toContain('npx ruflo@latest proxy update');
});
it('stays silent when the installed release already matches the pin', async () => {
const { proxyUpdateGuidance, DEFAULT_PROXY_RELEASE } = await import('../src/commands/proxy-lifecycle.js');
expect(proxyUpdateGuidance(installedAt(DEFAULT_PROXY_RELEASE))).toEqual([]);
});
/** Unknown is not "current" — claiming either way from no evidence is the bug. */
it('stays silent when the installed release is unknown', async () => {
const { proxyUpdateGuidance } = await import('../src/commands/proxy-lifecycle.js');
expect(proxyUpdateGuidance(installedAt(null))).toEqual([]);
});
it('stays silent when nothing is installed', async () => {
const { proxyUpdateGuidance } = await import('../src/commands/proxy-lifecycle.js');
expect(proxyUpdateGuidance({ ...installedAt('0.4.0'), installed: false })).toEqual([]);
});
it('surfaces the drift through the console guidance a running proxy shows', async () => {
const { proxyConsoleGuidance } = await import('../src/commands/proxy-lifecycle.js');
const lines = proxyConsoleGuidance({ ...installedAt('0.4.0'), running: true, pid: 4242 }).join('\n');
expect(lines).toContain('Meta Proxy is ready.');
expect(lines).toContain('An update is available');
});
});
describe('getProxyStatus version reporting', () => {
it('reads the installed release from the install manifest', async () => {
const { proxyBinaryPath, proxyInstallManifestPath } = await import('../src/proxy/paths.js');
fs.mkdirSync(path.dirname(proxyBinaryPath()), { recursive: true });
fs.writeFileSync(proxyBinaryPath(), 'test binary marker');
fs.mkdirSync(path.dirname(proxyInstallManifestPath()), { recursive: true });
fs.writeFileSync(proxyInstallManifestPath(), JSON.stringify({ version: '0.4.0', sha256: 'abc' }));
const { getProxyStatus } = await import('../src/proxy/lifecycle.js');
expect(getProxyStatus()).toMatchObject({ installed: true, version: '0.4.0' });
});
it('reports an unreadable manifest as unknown rather than throwing', async () => {
const { proxyBinaryPath, proxyInstallManifestPath } = await import('../src/proxy/paths.js');
fs.mkdirSync(path.dirname(proxyBinaryPath()), { recursive: true });
fs.writeFileSync(proxyBinaryPath(), 'test binary marker');
fs.mkdirSync(path.dirname(proxyInstallManifestPath()), { recursive: true });
fs.writeFileSync(proxyInstallManifestPath(), 'not json{');
const { getProxyStatus } = await import('../src/proxy/lifecycle.js');
expect(getProxyStatus()).toMatchObject({ installed: true, version: null });
});
it('reports no version when nothing is installed', async () => {
const { getProxyStatus } = await import('../src/proxy/lifecycle.js');
expect(getProxyStatus()).toMatchObject({ installed: false, version: null });
});
});