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
22 changes: 15 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createContext } from './context.ts';
import { getEnvironment, isTelemetryDisabled } from './environment.ts';
import { welcomeBannerBody, welcomeBannerTitle } from './interactive/banner.ts';
import { openReport } from './interactive/openReport.ts';
import { runSharePrompt } from './interactive/sharePrompt.ts';
import { runSharePrompt, shouldRequestReportShare, showLocalReportReadyNotice } from './interactive/sharePrompt.ts';
import { formatInteractiveTokenError, interactiveResolveToken } from './interactive/tokenWalkthrough.ts';
import { enforceTty } from './interactive/ttyGate.ts';
import { IoImpl } from './IoImpl.ts';
Expand Down Expand Up @@ -90,12 +90,20 @@ const result = await main(ctx, argv);

if (result.kind === 'completed') {
await openReport({ context: ctx, htmlPath: result.run.paths.html });
await runSharePrompt({
context: ctx,
target: result.run.target,
htmlPath: result.run.paths.html,
htmlContent: result.run.html,
});
if (shouldRequestReportShare(ctx)) {
await runSharePrompt({
context: ctx,
target: result.run.target,
htmlPath: result.run.paths.html,
htmlContent: result.run.html,
});
} else {
showLocalReportReadyNotice({
context: ctx,
target: result.run.target,
htmlPath: result.run.paths.html,
});
}
}

await shutdown();
Expand Down
19 changes: 17 additions & 2 deletions src/interactive/sharePrompt.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import { describe, expect, test } from 'bun:test';
import { fakeContextHandle } from '../testHelpers/testFactories.ts';
import { runSharePrompt } from './sharePrompt.ts';
import { runSharePrompt, shouldRequestReportShare, showLocalReportReadyNotice } from './sharePrompt.ts';
import { sharePromptInputsFor } from './testFactories.ts';

describe('runSharePrompt', () => {
describe('report sharing prompt', () => {
test('does not request report sharing when do not track disables telemetry', () => {
const handle = fakeContextHandle.build();
const context = { ...handle.ctx, env: { ...handle.ctx.env, DO_NOT_TRACK: true }, telemetryDisabled: true };

showLocalReportReadyNotice({ context, target: 'acme', htmlPath: '/tmp/report.html' });

expect(shouldRequestReportShare(context)).toBe(false);
expect(handle.prompter.selects).toHaveLength(0);
expect(handle.prompter.texts).toHaveLength(0);
expect(handle.uploader.calls).toHaveLength(0);
expect(handle.prompter.notes[0]).toMatchObject({
title: 'Report ready',
});
expect(handle.prompter.notes[0]?.message).toContain('Nothing was uploaded because tracking is disabled.');
});
test('shows the report path and a clear share question, defaulting to sharing', async () => {
const handle = fakeContextHandle.build();
handle.prompter.scriptSelect('declined');
Expand Down
23 changes: 22 additions & 1 deletion src/interactive/sharePrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ const SUPPORT_LINE = 'Reach us at founders@contextbridge.ai — or learn more at

export type ShareChoice = 'html' | 'declined';

export interface SharePromptInputs {
export interface ReportReadyNoticeInputs {
readonly context: Context;
readonly target: string;
readonly htmlPath: string;
}

export interface SharePromptInputs extends ReportReadyNoticeInputs {
readonly htmlContent: string;
}

Expand All @@ -19,6 +22,24 @@ export type ShareOutcome =
| { kind: 'cancelled' }
| { kind: 'upload-failed'; message: string };

export function shouldRequestReportShare(context: Context): boolean {
return !context.telemetryDisabled;
}

export function showLocalReportReadyNotice(inputs: ReportReadyNoticeInputs): void {
const { prompter } = inputs.context;
prompter.note(
[
`Scanned: ${inputs.target}`,
`HTML report: ${inputs.htmlPath}`,
'',
'Nothing was uploaded because tracking is disabled.',
].join('\n'),
'Report ready',
);
prompter.outro('Done.');
}

export async function runSharePrompt(inputs: SharePromptInputs): Promise<ShareOutcome> {
const { prompter, analytics, uploader } = inputs.context;

Expand Down