@myrialabs/clopen 0.4.28 → 0.4.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/backend/auth/auth-service.ts +45 -25
- package/backend/auth/onboarding.test.ts +106 -0
- package/backend/auth/permissions.ts +1 -1
- package/backend/database/utils/connection.ts +7 -31
- package/backend/engine/README.md +8 -3
- package/backend/engine/adapters/claude/message-converter.ts +51 -0
- package/backend/engine/adapters/codex/message-converter.ts +8 -2
- package/backend/engine/adapters/codex/models.ts +85 -98
- package/backend/engine/adapters/codex/stream.ts +5 -7
- package/backend/engine/adapters/codex/usage-rollout.ts +7 -0
- package/backend/engine/adapters/copilot/stream.ts +24 -0
- package/backend/engine/docs/lessons-learned.md +78 -1
- package/backend/engine/docs/stack.md +8 -0
- package/backend/engine/install-recipes.ts +19 -2
- package/backend/files/file-size-limit.ts +5 -14
- package/backend/files/file-watcher.test.ts +160 -0
- package/backend/files/file-watcher.ts +276 -58
- package/backend/git/git-executor.ts +8 -0
- package/backend/git/git-service.test.ts +136 -0
- package/backend/git/git-service.ts +113 -17
- package/backend/index.ts +11 -4
- package/backend/mcp/internal/remote-server.test.ts +8 -3
- package/backend/mcp/internal/remote-server.ts +1 -1
- package/backend/settings/system-settings.ts +97 -0
- package/backend/tunnel/public-origin.ts +5 -13
- package/backend/utils/env.ts +29 -0
- package/backend/utils/paths.ts +9 -3
- package/backend/ws/auth/login.test.ts +8 -1
- package/backend/ws/auth/login.ts +22 -15
- package/backend/ws/auth/status.ts +24 -1
- package/backend/ws/chat/stream.ts +1 -0
- package/backend/ws/files/watch.ts +9 -0
- package/backend/ws/settings/crud.ts +14 -22
- package/dist/assets/{index-BujQYGBm.js → index-C7e5TWG3.js} +1 -1
- package/dist/assets/{index-DRMOgS9y.js → index-Derlqeyy.js} +1 -1
- package/dist/assets/{main-BrqMMMRX.css → main-CqzaPnux.css} +1 -1
- package/dist/assets/main-OGhsRKU1.js +1037 -0
- package/dist/index.html +2 -2
- package/package.json +14 -14
- package/shared/constants/engines.ts +1 -0
- package/shared/types/stores/settings.ts +11 -1
- package/shared/types/unified/stream.ts +10 -4
- package/dist/assets/main-BrYtWn-4.js +0 -1036
|
@@ -543,6 +543,30 @@ export class CopilotEngine implements AIEngine {
|
|
|
543
543
|
finished = true;
|
|
544
544
|
break;
|
|
545
545
|
|
|
546
|
+
case 'session_limits_exhausted.requested': {
|
|
547
|
+
// Added in @github/copilot-sdk 1.0.9. The model request is
|
|
548
|
+
// BLOCKED until a client answers this over `rpc.ui` — an
|
|
549
|
+
// unhandled one hangs the turn with no output at all.
|
|
550
|
+
//
|
|
551
|
+
// The available actions are `add` / `set` / `unset` / `cancel`,
|
|
552
|
+
// i.e. three of them raise (or remove) the user's AI-credit
|
|
553
|
+
// ceiling. Clopen never spends on someone's behalf, so it
|
|
554
|
+
// cancels the blocked request and reports the numbers; raising
|
|
555
|
+
// the limit stays a deliberate act in GitHub's own settings.
|
|
556
|
+
const { requestId, usedAiCredits, maxAiCredits } = event.data;
|
|
557
|
+
void session.rpc.ui
|
|
558
|
+
.handlePendingSessionLimitsExhausted({ requestId, response: { action: 'cancel' } })
|
|
559
|
+
.catch((error: unknown) => debug.warn('engine', 'Copilot session-limit cancel failed:', error));
|
|
560
|
+
yield {
|
|
561
|
+
type: 'notification',
|
|
562
|
+
sessionId: state.sessionId,
|
|
563
|
+
level: 'error',
|
|
564
|
+
title: 'Copilot AI credit limit reached',
|
|
565
|
+
message: `This session used ${usedAiCredits} of ${maxAiCredits} AI credits, so the request was cancelled. Raise the limit in your GitHub Copilot settings to continue.`,
|
|
566
|
+
};
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
569
|
+
|
|
546
570
|
case 'session.error':
|
|
547
571
|
throw buildSessionError(event.data);
|
|
548
572
|
|
|
@@ -248,7 +248,7 @@ resume.
|
|
|
248
248
|
|-----------|----------------------------------------------------------------------------------------------|
|
|
249
249
|
| Claude | Pass `forkSession: true` in the SDK options on every call — native. |
|
|
250
250
|
| OpenCode | Call `client.session.fork({ path: { id: resume } })` on every resume — native. |
|
|
251
|
-
| Copilot | Call `client.rpc.sessions.fork({ sessionId: resume })` on every resume — native (
|
|
251
|
+
| Copilot | Call `client.rpc.sessions.fork({ sessionId: resume })` on every resume — native (added in `@github/copilot-sdk` 1.0.0-beta.4; still marked `@experimental` in 1.0.9, so keep the fallback-to-plain-resume path). |
|
|
252
252
|
| Codex | **No native API yet** — fork by copying the rollout JSONL FILE on every resume. |
|
|
253
253
|
| Qwen Code | **No native API yet** — fork by copying the chat JSONL FILE on every resume. |
|
|
254
254
|
| Pi | `SessionManager.forkFrom()` on the on-disk JSONL tree (in Clopen's isolated sessions dir) — native, on every resume. |
|
|
@@ -1431,3 +1431,80 @@ reachable, so smuggling the import into some other boot-path file is caught
|
|
|
1431
1431
|
too. It also asserts each key loads *its own* adapter: mapping `cursor` to
|
|
1432
1432
|
`ClineEngine` type-checks with zero errors and would route a user's chat
|
|
1433
1433
|
through the wrong SDK, and nothing but that check catches it.
|
|
1434
|
+
|
|
1435
|
+
---
|
|
1436
|
+
|
|
1437
|
+
### 10.25 Upgrading engine SDKs — the type-checker only sees half of it
|
|
1438
|
+
|
|
1439
|
+
The August 2026 pass moved all eleven engine packages to current (Claude
|
|
1440
|
+
0.3.158 → 0.3.229, Copilot beta.9 → 1.0.9 + CLI 1.0.55 → 1.0.79, Codex 0.135 →
|
|
1441
|
+
0.147, OpenCode 1.15.12 → 1.18.18, Pi 0.80.10 → 0.84.1, Cline 0.0.65 → 0.0.74,
|
|
1442
|
+
Cursor 1.0.24 → 1.0.27, Qwen 0.1.7 → 0.1.8). `bun run check` reported exactly
|
|
1443
|
+
two errors — and neither of them was one of the three real problems. What the
|
|
1444
|
+
type-checker cannot see is where the work is:
|
|
1445
|
+
|
|
1446
|
+
- **A new *blocking* event is a hang, not a type error.** Copilot 1.0.9 added
|
|
1447
|
+
`session_limits_exhausted.requested`: the model request stops until a client
|
|
1448
|
+
answers it over `session.rpc.ui.handlePendingSessionLimitsExhausted`. An
|
|
1449
|
+
unhandled `case` compiles perfectly and the turn simply never produces
|
|
1450
|
+
output. Before shipping an upgrade, diff the event union for anything named
|
|
1451
|
+
`*.requested` / `*.asked` / `*_request` and check whether it has a paired
|
|
1452
|
+
`.completed` — that pairing is the tell for "someone must answer this".
|
|
1453
|
+
Clopen answers `cancel` and surfaces a notification: three of the four
|
|
1454
|
+
actions raise the user's AI-credit ceiling, and no auto-approval policy
|
|
1455
|
+
covers spending someone's money.
|
|
1456
|
+
|
|
1457
|
+
- **A new *informational* message type is silent data loss.** Claude's
|
|
1458
|
+
`SDKMessage` grew eight members; two of them (`model_refusal_fallback`,
|
|
1459
|
+
`model_refusal_no_fallback`) are precisely the cases a user notices — the
|
|
1460
|
+
answer came from a model they did not pick, or no answer came at all — and
|
|
1461
|
+
the converter's `default` arm swallowed both. Adapters end their dispatch
|
|
1462
|
+
with a catch-all by design, so every SDK bump must diff the union rather than
|
|
1463
|
+
trust a clean compile.
|
|
1464
|
+
|
|
1465
|
+
- **A static model catalog goes stale on the same clock, and the CLI knows the
|
|
1466
|
+
answer.** The Codex bump moved the whole lineup: `gpt-5.6-sol/terra/luna`
|
|
1467
|
+
appeared, `gpt-5.3-codex` and the `gpt-5.4` pair left, `gpt-5.5` stopped being
|
|
1468
|
+
ChatGPT-only, the context window went 200k → 272k, `minimal` stopped being a
|
|
1469
|
+
valid effort and `max`/`ultra` became one. None of that surfaces as a type
|
|
1470
|
+
error — a wrong slug fails at runtime, inside the CLI, as somebody's chat.
|
|
1471
|
+
Do not transcribe the docs: the shipped binary embeds its own preset table
|
|
1472
|
+
(`strings <codex-binary>`, search `"models": [`) with slug, `display_name`,
|
|
1473
|
+
`context_window`, `default_reasoning_level`, `supported_reasoning_levels`,
|
|
1474
|
+
`visibility` and `priority`. That is what the client actually accepts, and
|
|
1475
|
+
`backend/engine/adapters/codex/models.ts` mirrors it field for field. Treat
|
|
1476
|
+
the public docs as the second source, not the first — and remember the CLI
|
|
1477
|
+
also fetches account-entitled models from the server, so absence from the
|
|
1478
|
+
embedded table is not proof of removal (that is why `gpt-5.3-codex-spark`
|
|
1479
|
+
stayed).
|
|
1480
|
+
|
|
1481
|
+
- **Peer dependencies float even when the SDK is pinned.**
|
|
1482
|
+
`@anthropic-ai/claude-agent-sdk` ships no dependencies: `@anthropic-ai/sdk`,
|
|
1483
|
+
`@modelcontextprotocol/sdk` and `zod` are peers. `ENGINE_PACKAGES` listed
|
|
1484
|
+
only the SDK, so `bun add` resolved all three at `@latest` inside
|
|
1485
|
+
`~/.clopen/stack/engines` — a real install carried `@anthropic-ai/sdk`
|
|
1486
|
+
0.115.0 while clopen type-checked against its pinned 0.100.1. Same class as
|
|
1487
|
+
the typebox float (#362). The peers are pinned explicitly now. When adding an
|
|
1488
|
+
engine, read its `peerDependencies`, not just its `dependencies`.
|
|
1489
|
+
|
|
1490
|
+
**Known gap, deliberately not closed:** `SDKModelRefusalFallbackMessage`
|
|
1491
|
+
carries `retracted_message_uuids` — messages the CLI has *withdrawn* after
|
|
1492
|
+
delivering them. Clopen's `messageId` for Claude is the SDK uuid, so honouring
|
|
1493
|
+
it is feasible, but it needs a retraction event threaded through
|
|
1494
|
+
adapter → stream-manager → WS → frontend removal. Until then the refused
|
|
1495
|
+
partial stays in the transcript above the fallback answer, and the toast is
|
|
1496
|
+
what explains it.
|
|
1497
|
+
|
|
1498
|
+
A second gap worth naming: the SDK's own types can lag the CLI it drives.
|
|
1499
|
+
`ModelReasoningEffort` still stops at `xhigh` in codex-sdk 0.147 while the CLI
|
|
1500
|
+
enum runs to `max` and `ultra`, and the SDK never validates — it interpolates
|
|
1501
|
+
the string into `--config model_reasoning_effort="…"`. Reading the transport,
|
|
1502
|
+
not just the type, is what made GPT-5.6's top levels reachable. Cast at the SDK
|
|
1503
|
+
boundary and gate the value in one place (`resolveCodexEffort`), never by a
|
|
1504
|
+
second copy of the allow-list next to the call site — that copy is exactly what
|
|
1505
|
+
had gone stale.
|
|
1506
|
+
|
|
1507
|
+
The mechanical part of an upgrade is cheap; budget the time for the union
|
|
1508
|
+
diffs. `/tmp`-installing the old and new versions side by side and diffing the
|
|
1509
|
+
`type: "…"` literals in each SDK's event declarations found every item above in
|
|
1510
|
+
minutes.
|
|
@@ -125,6 +125,14 @@ Engine SDKs don't need a hand-written resolver. When you add an engine
|
|
|
125
125
|
clopen imports and detects install-state from; extras pin a transitive CLI
|
|
126
126
|
the SDK would otherwise float). Add the same packages to `package.json`
|
|
127
127
|
`devDependencies` at an exact version — that is the single source of truth.
|
|
128
|
+
**Read the SDK's `peerDependencies` too.** A peer the SDK ships no copy of
|
|
129
|
+
resolves at `@latest` inside the stack dir unless it is listed here, leaving
|
|
130
|
+
clopen type-checked against one version and running another —
|
|
131
|
+
`@anthropic-ai/claude-agent-sdk` has `@anthropic-ai/sdk`,
|
|
132
|
+
`@modelcontextprotocol/sdk` and `zod` listed for exactly that reason (see
|
|
133
|
+
[lessons-learned](./lessons-learned.md) §10.25). A package the SDK depends
|
|
134
|
+
on *directly* needs no entry: its own range governs, and bun nests a copy
|
|
135
|
+
when two engines disagree.
|
|
128
136
|
3. `resolveEngineRecipe(tool)` handles the rest automatically (installs into the
|
|
129
137
|
stack dir at the pinned version).
|
|
130
138
|
4. Add the literal to `TOOL_UNION` (`status.ts`, `install.ts`).
|
|
@@ -84,7 +84,19 @@ export interface ToolStatus {
|
|
|
84
84
|
/**
|
|
85
85
|
* Engine → the npm package(s) clopen must install to run that engine on demand.
|
|
86
86
|
* The FIRST entry is the SDK clopen imports (used for install-state detection);
|
|
87
|
-
* any extras pin
|
|
87
|
+
* any extras pin something the SDK would otherwise float — a transitive CLI
|
|
88
|
+
* (copilot), a sibling package (pi, cline), or an unmet PEER dependency.
|
|
89
|
+
*
|
|
90
|
+
* Peers are the subtle case. `@anthropic-ai/claude-agent-sdk` declares
|
|
91
|
+
* `@anthropic-ai/sdk`, `@modelcontextprotocol/sdk` and `zod` as peers and ships
|
|
92
|
+
* no copy of its own, so installing the SDK alone lets bun resolve all three at
|
|
93
|
+
* `@latest` inside the stack dir — clopen would then type-check against the
|
|
94
|
+
* versions in its own package.json while the adapter loads different ones at
|
|
95
|
+
* runtime (observed: pinned `@anthropic-ai/sdk` 0.100.1 vs 0.115.0 installed).
|
|
96
|
+
* Listing them here holds them to the same pin. Engines whose SDK depends on
|
|
97
|
+
* these packages directly (copilot, cursor, qwen) need no entry: their own
|
|
98
|
+
* range governs, and bun nests a separate copy when it disagrees.
|
|
99
|
+
*
|
|
88
100
|
* Versions are read from package.json (the single source of truth), so an
|
|
89
101
|
* on-demand install always matches the exact version clopen was tested against.
|
|
90
102
|
* Every package listed here must therefore be declared in package.json —
|
|
@@ -92,7 +104,12 @@ export interface ToolStatus {
|
|
|
92
104
|
* silently install as `@latest`.
|
|
93
105
|
*/
|
|
94
106
|
export const ENGINE_PACKAGES: Partial<Record<ToolId, string[]>> = {
|
|
95
|
-
claude: [
|
|
107
|
+
claude: [
|
|
108
|
+
'@anthropic-ai/claude-agent-sdk',
|
|
109
|
+
'@anthropic-ai/sdk',
|
|
110
|
+
'@modelcontextprotocol/sdk',
|
|
111
|
+
'zod'
|
|
112
|
+
],
|
|
96
113
|
opencode: ['@opencode-ai/sdk'],
|
|
97
114
|
copilot: ['@github/copilot-sdk', '@github/copilot'],
|
|
98
115
|
codex: ['@openai/codex-sdk'],
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* defaults to 500MB when the setting is missing or invalid.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { readSystemSetting } from '../settings/system-settings';
|
|
11
11
|
|
|
12
12
|
/** Default maximum file size in megabytes when no admin setting is present. */
|
|
13
13
|
export const DEFAULT_MAX_FILE_SIZE_MB = 500;
|
|
@@ -19,19 +19,10 @@ export const DEFAULT_MAX_FILE_SIZE_MB = 500;
|
|
|
19
19
|
* (e.g. on first boot before the admin writes any system setting).
|
|
20
20
|
*/
|
|
21
21
|
export function getMaxFileSize(): number {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const parsed = typeof row.value === 'string' ? JSON.parse(row.value) : row.value;
|
|
27
|
-
const candidate = Number(parsed?.maxFileSizeMB);
|
|
28
|
-
if (Number.isFinite(candidate) && candidate > 0) {
|
|
29
|
-
limitMB = candidate;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
} catch {
|
|
33
|
-
// Fall back to default on any read/parse failure.
|
|
34
|
-
}
|
|
22
|
+
const limitMB = readSystemSetting((settings) => {
|
|
23
|
+
const candidate = Number(settings.maxFileSizeMB);
|
|
24
|
+
return Number.isFinite(candidate) && candidate > 0 ? candidate : undefined;
|
|
25
|
+
}, DEFAULT_MAX_FILE_SIZE_MB);
|
|
35
26
|
return Math.floor(limitMB * 1024 * 1024);
|
|
36
27
|
}
|
|
37
28
|
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File watcher tests.
|
|
3
|
+
*
|
|
4
|
+
* These exercise the real watcher against a real temp directory, because the
|
|
5
|
+
* bugs this code exists to prevent are all about what the OS actually reports:
|
|
6
|
+
* ignored directories still generating events, a rebuilt watcher announcing
|
|
7
|
+
* itself as a file change, and nested directories created after start-up going
|
|
8
|
+
* unwatched (which is only a risk on the platforms where recursion is emulated).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { describe, expect, mock, test, beforeAll, afterEach } from 'bun:test';
|
|
12
|
+
import { mkdtemp, mkdir, rm, writeFile } from 'node:fs/promises';
|
|
13
|
+
import { tmpdir } from 'node:os';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
|
|
16
|
+
interface Emitted {
|
|
17
|
+
projectId: string;
|
|
18
|
+
event: string;
|
|
19
|
+
payload: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const emitted: Emitted[] = [];
|
|
23
|
+
|
|
24
|
+
mock.module('$backend/utils/ws', () => ({
|
|
25
|
+
ws: {
|
|
26
|
+
emit: {
|
|
27
|
+
project: (projectId: string, event: string, payload: Record<string, unknown>) => {
|
|
28
|
+
emitted.push({ projectId, event, payload });
|
|
29
|
+
},
|
|
30
|
+
user: () => {},
|
|
31
|
+
global: () => {}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
// Imported after the mock so the watcher binds to the stub.
|
|
37
|
+
let fileWatcher: typeof import('./file-watcher').fileWatcher;
|
|
38
|
+
|
|
39
|
+
beforeAll(async () => {
|
|
40
|
+
({ fileWatcher } = await import('./file-watcher'));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const tempRoots: string[] = [];
|
|
44
|
+
|
|
45
|
+
async function makeProject(): Promise<string> {
|
|
46
|
+
const dir = await mkdtemp(join(tmpdir(), 'clopen-watch-'));
|
|
47
|
+
tempRoots.push(dir);
|
|
48
|
+
return dir;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Wait until `predicate` holds, or fail after `timeout` ms. */
|
|
52
|
+
async function waitFor(predicate: () => boolean, timeout = 4000): Promise<void> {
|
|
53
|
+
const deadline = Date.now() + timeout;
|
|
54
|
+
while (Date.now() < deadline) {
|
|
55
|
+
if (predicate()) return;
|
|
56
|
+
await new Promise((r) => setTimeout(r, 25));
|
|
57
|
+
}
|
|
58
|
+
throw new Error('Timed out waiting for watcher event');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function changesFor(projectId: string): string[] {
|
|
62
|
+
return emitted
|
|
63
|
+
.filter((e) => e.projectId === projectId && e.event === 'files:changed')
|
|
64
|
+
.flatMap((e) => (e.payload.changes as { path: string }[]).map((c) => c.path));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
afterEach(async () => {
|
|
68
|
+
for (const projectId of fileWatcher.getWatchedProjects()) {
|
|
69
|
+
fileWatcher.releaseProject(projectId);
|
|
70
|
+
}
|
|
71
|
+
emitted.length = 0;
|
|
72
|
+
await Promise.all(tempRoots.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('FileWatcherManager', () => {
|
|
76
|
+
test('reports changes to files in the project root', async () => {
|
|
77
|
+
const root = await makeProject();
|
|
78
|
+
expect(await fileWatcher.startWatching('p1', root)).toBe(true);
|
|
79
|
+
|
|
80
|
+
await writeFile(join(root, 'index.ts'), 'export {}');
|
|
81
|
+
|
|
82
|
+
await waitFor(() => changesFor('p1').some((p) => p.endsWith('index.ts')));
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('reports changes in nested directories created after the watch started', async () => {
|
|
86
|
+
const root = await makeProject();
|
|
87
|
+
expect(await fileWatcher.startWatching('p2', root)).toBe(true);
|
|
88
|
+
|
|
89
|
+
// A directory that did not exist at start-up: on Linux this only works if
|
|
90
|
+
// the watcher attaches to newly created directories as it sees them.
|
|
91
|
+
const nested = join(root, 'src', 'deep');
|
|
92
|
+
await mkdir(nested, { recursive: true });
|
|
93
|
+
await waitFor(() => changesFor('p2').some((p) => p.endsWith('src')));
|
|
94
|
+
|
|
95
|
+
emitted.length = 0;
|
|
96
|
+
await writeFile(join(nested, 'mod.ts'), 'export {}');
|
|
97
|
+
|
|
98
|
+
await waitFor(() => changesFor('p2').some((p) => p.endsWith('mod.ts')));
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('never reports changes inside ignored directories', async () => {
|
|
102
|
+
const root = await makeProject();
|
|
103
|
+
await mkdir(join(root, 'node_modules', 'pkg'), { recursive: true });
|
|
104
|
+
await mkdir(join(root, '.git'), { recursive: true });
|
|
105
|
+
expect(await fileWatcher.startWatching('p3', root)).toBe(true);
|
|
106
|
+
|
|
107
|
+
await writeFile(join(root, 'node_modules', 'pkg', 'index.js'), '// noise');
|
|
108
|
+
await writeFile(join(root, '.git', 'COMMIT_EDITMSG'), 'wip');
|
|
109
|
+
|
|
110
|
+
// Space the writes out: the platform watchers coalesce bursts and can drop
|
|
111
|
+
// events that land in the same instant, which would make this pass for the
|
|
112
|
+
// wrong reason (or fail on the sentinel write below).
|
|
113
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
114
|
+
|
|
115
|
+
// Write a watched file last; once it lands, the ignored writes have had at
|
|
116
|
+
// least as long to arrive, so their absence is meaningful rather than a race.
|
|
117
|
+
await writeFile(join(root, 'app.ts'), 'export {}');
|
|
118
|
+
await waitFor(() => changesFor('p3').some((p) => p.endsWith('app.ts')));
|
|
119
|
+
|
|
120
|
+
const paths = changesFor('p3');
|
|
121
|
+
expect(paths.some((p) => p.includes('node_modules'))).toBe(false);
|
|
122
|
+
expect(paths.some((p) => p.includes('.git'))).toBe(false);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('does not emit an empty change list', async () => {
|
|
126
|
+
const root = await makeProject();
|
|
127
|
+
expect(await fileWatcher.startWatching('p4', root)).toBe(true);
|
|
128
|
+
|
|
129
|
+
await writeFile(join(root, 'a.ts'), 'export {}');
|
|
130
|
+
await waitFor(() => changesFor('p4').length > 0);
|
|
131
|
+
|
|
132
|
+
const empties = emitted.filter(
|
|
133
|
+
(e) => e.event === 'files:changed' && (e.payload.changes as unknown[]).length === 0
|
|
134
|
+
);
|
|
135
|
+
expect(empties).toHaveLength(0);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('tracks dirty files for the snapshot system', async () => {
|
|
139
|
+
const root = await makeProject();
|
|
140
|
+
expect(await fileWatcher.startWatching('p5', root)).toBe(true);
|
|
141
|
+
|
|
142
|
+
await writeFile(join(root, 'tracked.ts'), 'export {}');
|
|
143
|
+
await waitFor(() => fileWatcher.getDirtyFiles('p5').has('tracked.ts'));
|
|
144
|
+
|
|
145
|
+
fileWatcher.clearDirtyFiles('p5');
|
|
146
|
+
expect(fileWatcher.getDirtyFiles('p5').size).toBe(0);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('stops watching once the last viewer leaves', async () => {
|
|
150
|
+
const root = await makeProject();
|
|
151
|
+
expect(await fileWatcher.addViewer('conn-a', 'p6', root)).toBe(true);
|
|
152
|
+
expect(await fileWatcher.addViewer('conn-b', 'p6', root)).toBe(true);
|
|
153
|
+
|
|
154
|
+
fileWatcher.removeViewer('conn-a', 'p6');
|
|
155
|
+
expect(fileWatcher.isWatching('p6')).toBe(true);
|
|
156
|
+
|
|
157
|
+
fileWatcher.removeViewer('conn-b', 'p6');
|
|
158
|
+
expect(fileWatcher.isWatching('p6')).toBe(false);
|
|
159
|
+
});
|
|
160
|
+
});
|