Skip to content

Commit 189b062

Browse files
authored
refactor: extract client/ folder — Phase 5 (#960)
Move the SDK client + companion-tunnel cluster out of the src/ root into a dedicated src/client/ folder, per plans/perfect-shape.md §5.5 (~8k LOC client/remote unfoldered at src root; remote/ already extracted in #951). Files moved (9): client, client-types, client-shared, client-normalizers, client-companion-tunnel{,-contract,-worker}, client-react-devtools-companion, companion-tunnel. - git renames; 68 importers repointed via the resolve-based codemod (intra-client stays ./, staying deps recomputed) - companion-tunnel.ts keeps rslib key 'internal/companion-tunnel' so dist output stays dist/src/internal/companion-tunnel.js (public subpath byte-identical; verified by build) - update non-src importers (3 integration tests, vitest coverage include), .fallowrc.json entrypoint, fallow-baselines/health.json keys backend.ts and daemon-client*.ts are intentionally left for follow-up (daemon/client split). Behaviorless path codemod; all gates green.
1 parent 531aad7 commit 189b062

78 files changed

Lines changed: 176 additions & 169 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.fallowrc.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"src/selectors.ts",
1515
"src/finders.ts",
1616
"src/bin.ts",
17-
"src/companion-tunnel.ts",
17+
"src/client/companion-tunnel.ts",
1818
"src/daemon.ts",
1919
"src/utils/png-worker.ts",
2020
"scripts/patch-xcuitest-runner-icon.ts",

‎fallow-baselines/health.json‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@
7474
"count": 1
7575
}
7676
},
77-
"src/client-companion-tunnel-worker.ts": {
77+
"src/client/client-companion-tunnel-worker.ts": {
7878
"complexity_high": {
7979
"count": 1
8080
},
8181
"crap_moderate": {
8282
"count": 3
8383
}
8484
},
85-
"src/client-companion-tunnel.ts": {
85+
"src/client/client-companion-tunnel.ts": {
8686
"crap_high": {
8787
"count": 2
8888
},
@@ -95,7 +95,7 @@
9595
"count": 3
9696
}
9797
},
98-
"src/client-shared.ts": {
98+
"src/client/client-shared.ts": {
9999
"crap_moderate": {
100100
"count": 1
101101
}
@@ -688,7 +688,7 @@
688688
"src/snapshot/snapshot-processing.ts:high impact",
689689
"src/daemon/handlers/session-device-utils.ts:high impact",
690690
"src/commands/cli-grammar/common.ts:high impact",
691-
"src/client-shared.ts:high impact",
691+
"src/client/client-shared.ts:high impact",
692692
"src/replay/script.ts:complexity",
693693
"src/commands/selector-read-utils.ts:high impact",
694694
"src/core/interaction-targeting.ts:high impact",
@@ -736,6 +736,6 @@
736736
"src/platforms/android/app-parsers.ts:high impact",
737737
"src/utils/source-value.ts:high impact",
738738
"src/platforms/android/sdk.ts:high impact",
739-
"src/client-companion-tunnel-worker.ts:complexity"
739+
"src/client/client-companion-tunnel-worker.ts:complexity"
740740
]
741741
}

‎rslib.config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default defineConfig({
3535
selectors: 'src/selectors.ts',
3636
finders: 'src/finders.ts',
3737
'internal/bin': 'src/bin.ts',
38-
'internal/companion-tunnel': 'src/companion-tunnel.ts',
38+
'internal/companion-tunnel': 'src/client/companion-tunnel.ts',
3939
'internal/daemon': 'src/daemon.ts',
4040
'internal/png-worker': 'src/utils/png-worker.ts',
4141
'internal/update-check-entry': 'src/utils/update-check-entry.ts',

‎src/__tests__/cli-client-commands.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import type {
1212
AppOpenOptions,
1313
MetroPrepareOptions,
1414
MetroReloadOptions,
15-
} from '../client.ts';
16-
import type { SettingsUpdateOptions } from '../client-types.ts';
15+
} from '../client/client.ts';
16+
import type { SettingsUpdateOptions } from '../client/client-types.ts';
1717
import { AppError } from '../kernel/errors.ts';
1818
import { resolveCliOptions } from '../utils/cli-options.ts';
1919

‎src/__tests__/cli-react-devtools.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ vi.mock('../utils/exec.ts', () => ({
66
runCmdStreaming: vi.fn(),
77
}));
88

9-
vi.mock('../client-react-devtools-companion.ts', () => ({
9+
vi.mock('../client/client-react-devtools-companion.ts', () => ({
1010
ensureReactDevtoolsCompanion: vi.fn(),
1111
stopReactDevtoolsCompanion: vi.fn(),
1212
}));
@@ -15,7 +15,7 @@ import { runCmdStreaming } from '../utils/exec.ts';
1515
import {
1616
ensureReactDevtoolsCompanion,
1717
stopReactDevtoolsCompanion,
18-
} from '../client-react-devtools-companion.ts';
18+
} from '../client/client-react-devtools-companion.ts';
1919
import {
2020
AGENT_REACT_DEVTOOLS_PACKAGE,
2121
buildReactDevtoolsNpmExecArgs,

‎src/__tests__/client-companion-tunnel-worker.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { afterEach, test } from 'vitest';
1111
import {
1212
buildCompanionPayload,
1313
runCompanionTunnelWorker,
14-
} from '../client-companion-tunnel-worker.ts';
14+
} from '../client/client-companion-tunnel-worker.ts';
1515
import { closeLoopbackServer, listenOnLoopback } from './test-utils/index.ts';
1616

1717
type Deferred<T> = {
@@ -243,7 +243,11 @@ function spawnMetroCompanionWorker(options: {
243243
const localBaseUrl = options.localBaseUrl ?? `http://127.0.0.1:${options.localPort}`;
244244
const companion = spawn(
245245
process.execPath,
246-
['--experimental-strip-types', 'src/companion-tunnel.ts', '--agent-device-run-metro-companion'],
246+
[
247+
'--experimental-strip-types',
248+
'src/client/companion-tunnel.ts',
249+
'--agent-device-run-metro-companion',
250+
],
247251
{
248252
cwd: process.cwd(),
249253
env: {

‎src/__tests__/client-metro-companion.test.ts‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
waitForProcessExit,
2424
} from '../utils/process-identity.ts';
2525
import { ensureMetroCompanion, stopMetroCompanion } from '../metro/client-metro-companion.ts';
26-
import { ensureReactDevtoolsCompanion } from '../client-react-devtools-companion.ts';
26+
import { ensureReactDevtoolsCompanion } from '../client/client-react-devtools-companion.ts';
2727

2828
const TEST_BRIDGE_SCOPE = {
2929
tenantId: 'tenant-1',
@@ -41,7 +41,7 @@ function assertCompanionSpawnTarget(): void {
4141
assert.ok(firstCall, 'expected runCmdDetached to be called');
4242
assert.equal(firstCall[0], process.execPath);
4343
assert.ok(
44-
firstCall[1].some((arg) => arg.includes('src/companion-tunnel.ts')),
44+
firstCall[1].some((arg) => arg.includes('src/client/companion-tunnel.ts')),
4545
`expected companion entry path in ${JSON.stringify(firstCall[1])}`,
4646
);
4747
assert.equal(firstCall[1].at(-1), '--agent-device-run-metro-companion');
@@ -62,7 +62,7 @@ test('companion ownership is profile-scoped and consumer-counted', async () => {
6262
pid === 111 ? 'start-111' : 'start-222',
6363
);
6464
vi.mocked(readProcessCommand).mockImplementation(
65-
() => `${process.execPath} src/companion-tunnel.ts --agent-device-run-metro-companion`,
65+
() => `${process.execPath} src/client/companion-tunnel.ts --agent-device-run-metro-companion`,
6666
);
6767
vi.mocked(waitForProcessExit).mockResolvedValue(true);
6868
const killSpy = vi.spyOn(process, 'kill').mockImplementation(() => true);
@@ -161,7 +161,7 @@ test('launchUrl changes force a companion respawn for the same profile', async (
161161
pid === 333 ? 'start-333' : 'start-444',
162162
);
163163
vi.mocked(readProcessCommand).mockImplementation(
164-
() => `${process.execPath} src/companion-tunnel.ts --agent-device-run-metro-companion`,
164+
() => `${process.execPath} src/client/companion-tunnel.ts --agent-device-run-metro-companion`,
165165
);
166166
vi.mocked(waitForProcessExit).mockResolvedValue(true);
167167
const killSpy = vi.spyOn(process, 'kill').mockImplementation(() => true);
@@ -212,8 +212,8 @@ test('metro and React DevTools companions use distinct profile state paths', asy
212212
);
213213
vi.mocked(readProcessCommand).mockImplementation((pid) =>
214214
pid === 888
215-
? `${process.execPath} src/companion-tunnel.ts --agent-device-run-react-devtools-companion`
216-
: `${process.execPath} src/companion-tunnel.ts --agent-device-run-metro-companion`,
215+
? `${process.execPath} src/client/companion-tunnel.ts --agent-device-run-react-devtools-companion`
216+
: `${process.execPath} src/client/companion-tunnel.ts --agent-device-run-metro-companion`,
217217
);
218218

219219
const profileKey = '/tmp/shared-remote.json';
@@ -257,7 +257,7 @@ test('spawned companion uses neutral env names', async () => {
257257
vi.mocked(runCmdDetached).mockReturnValueOnce(999);
258258
vi.mocked(readProcessStartTime).mockReturnValue('start-999');
259259
vi.mocked(readProcessCommand).mockReturnValue(
260-
`${process.execPath} src/companion-tunnel.ts --agent-device-run-metro-companion`,
260+
`${process.execPath} src/client/companion-tunnel.ts --agent-device-run-metro-companion`,
261261
);
262262

263263
await ensureMetroCompanion({
@@ -298,7 +298,7 @@ test('state sentinel exists before spawning companion worker', async () => {
298298
});
299299
vi.mocked(readProcessStartTime).mockReturnValue('start-1001');
300300
vi.mocked(readProcessCommand).mockReturnValue(
301-
`${process.execPath} src/companion-tunnel.ts --agent-device-run-metro-companion`,
301+
`${process.execPath} src/client/companion-tunnel.ts --agent-device-run-metro-companion`,
302302
);
303303

304304
const spawned = await ensureMetroCompanion({
@@ -333,7 +333,7 @@ test('legacy state without bridge scope is stopped before respawn', async () =>
333333
`${JSON.stringify({
334334
pid: 555,
335335
startTime: 'start-555',
336-
command: `${process.execPath} src/companion-tunnel.ts --agent-device-run-metro-companion`,
336+
command: `${process.execPath} src/client/companion-tunnel.ts --agent-device-run-metro-companion`,
337337
serverBaseUrl: 'https://bridge.example.test',
338338
localBaseUrl: 'http://127.0.0.1:8081',
339339
tokenHash: 'legacy-token-hash',
@@ -345,7 +345,7 @@ test('legacy state without bridge scope is stopped before respawn', async () =>
345345
vi.mocked(isProcessAlive).mockReturnValue(true);
346346
vi.mocked(readProcessStartTime).mockReturnValue('start-555');
347347
vi.mocked(readProcessCommand).mockReturnValue(
348-
`${process.execPath} src/companion-tunnel.ts --agent-device-run-metro-companion`,
348+
`${process.execPath} src/client/companion-tunnel.ts --agent-device-run-metro-companion`,
349349
);
350350
vi.mocked(waitForProcessExit).mockResolvedValue(true);
351351
const killSpy = vi.spyOn(process, 'kill').mockImplementation(() => true);

‎src/__tests__/client-normalizers.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { test } from 'vitest';
22
import assert from 'node:assert/strict';
3-
import { normalizeOpenDevice } from '../client-normalizers.ts';
3+
import { normalizeOpenDevice } from '../client/client-normalizers.ts';
44
import { PLATFORMS } from '../kernel/device.ts';
55

66
test('normalizeOpenDevice accepts exactly the canonical leaf platforms', () => {

‎src/__tests__/client-shared.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
serializeOpenResult,
66
serializeSnapshotResult,
77
serializeSessionListEntry,
8-
} from '../client-shared.ts';
8+
} from '../client/client-shared.ts';
99

1010
test('serializeSessionListEntry preserves legacy android session payload shape', () => {
1111
const data = serializeSessionListEntry({

‎src/__tests__/client.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { test } from 'vitest';
22
import assert from 'node:assert/strict';
3-
import { createAgentDeviceClient, type AgentDeviceClientConfig } from '../client.ts';
3+
import { createAgentDeviceClient, type AgentDeviceClientConfig } from '../client/client.ts';
44
import { runCommand } from '../commands/command-surface.ts';
55
import type { DaemonRequest, DaemonResponse } from '../kernel/contracts.ts';
66
import { AppError } from '../kernel/errors.ts';

0 commit comments

Comments
 (0)