Skip to content
Merged
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
19 changes: 12 additions & 7 deletions frontend/src/v2/__tests__/byo-setup-command-invariant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ const fs = require('fs');
const path = require('path');
const { daemonSetupCommand } = require('../utils/daemonSetupCommand');

const SOURCES = [
'components/V2AgentBYO.tsx',
'components/V2AgentRuntimeGrants.tsx',
'components/V2ConnectPage.tsx',
];
const read = (rel) => fs.readFileSync(path.join(__dirname, '..', rel), 'utf8');
// Every v2 source file, not a fixed list: a new surface that hardcodes the host
// (the invite modal, Your Team, a future copy button) must fail here too.
const walk = (dir) => fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
const full = path.join(dir, entry.name);
if (entry.isDirectory()) return ['__tests__', '__mocks__'].includes(entry.name) ? [] : walk(full);
return /\.(tsx?|jsx?)$/.test(entry.name) && !/\.test\./.test(entry.name) ? [full] : [];
});
const V2_ROOT = path.join(__dirname, '..');
const SOURCES = walk(V2_ROOT).map((file) => path.relative(V2_ROOT, file));
const read = (rel) => fs.readFileSync(path.join(V2_ROOT, rel), 'utf8');

describe('copy-paste setup commands follow the page instance', () => {
beforeEach(() => { process.env.REACT_APP_API_URL = 'https://api-dev.example.test/'; });
Expand All @@ -24,7 +28,8 @@ describe('copy-paste setup commands follow the page instance', () => {
expect(command).not.toMatch(/commonly\.me/);
});

test('no BYO, Connect or runtime source hardcodes the production API host', () => {
test('no v2 source hardcodes the production API host', () => {
expect(SOURCES.length).toBeGreaterThan(20);
SOURCES.forEach((rel) => {
expect([rel, read(rel).match(/api\.commonly\.me/g)]).toEqual([rel, null]);
});
Expand Down
Loading