@myrialabs/clopen 0.4.33 → 0.4.35
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/permissions.ts +10 -0
- package/backend/auth/rate-limiter.test.ts +115 -0
- package/backend/auth/rate-limiter.ts +25 -12
- package/backend/containers/actions.ts +316 -0
- package/backend/containers/disk-usage.test.ts +68 -0
- package/backend/containers/disk-usage.ts +170 -0
- package/backend/containers/logs.ts +335 -0
- package/backend/containers/monitor.ts +410 -0
- package/backend/containers/parse.test.ts +599 -0
- package/backend/containers/parse.ts +905 -0
- package/backend/containers/port-index.test.ts +91 -0
- package/backend/containers/port-index.ts +198 -0
- package/backend/containers/prune-job.test.ts +148 -0
- package/backend/containers/prune-job.ts +129 -0
- package/backend/containers/pty-backend.ts +337 -0
- package/backend/containers/pty.ts +114 -0
- package/backend/containers/runtime.ts +218 -0
- package/backend/containers/scan.ts +293 -0
- package/backend/db-client/connection-manager.ts +13 -0
- package/backend/files/file-watcher.test.ts +105 -0
- package/backend/files/file-watcher.ts +45 -1
- package/backend/git/git-service.test.ts +33 -0
- package/backend/git/git-service.ts +7 -3
- package/backend/git/nested-repos.test.ts +292 -1
- package/backend/git/nested-repos.ts +330 -17
- package/backend/host/runner.ts +204 -0
- package/backend/index.ts +20 -2
- package/backend/middleware/security.test.ts +95 -0
- package/backend/middleware/security.ts +114 -0
- package/backend/ports/attribute.test.ts +231 -0
- package/backend/ports/attribute.ts +444 -0
- package/backend/ports/kill.ts +203 -0
- package/backend/ports/monitor.ts +365 -0
- package/backend/ports/processes.test.ts +98 -0
- package/backend/ports/processes.ts +374 -0
- package/backend/ports/registry.ts +165 -0
- package/backend/ports/scan-host.ts +329 -0
- package/backend/ports/scan.test.ts +341 -0
- package/backend/ports/scan.ts +687 -0
- package/backend/ports/ssh-lineage.ts +318 -0
- package/backend/preview/browser/browser-video-capture.ts +84 -31
- package/backend/ssh/forwards.ts +31 -0
- package/backend/ws/auth/device.ts +1 -1
- package/backend/ws/auth/login.ts +8 -4
- package/backend/ws/containers/actions.ts +156 -0
- package/backend/ws/containers/index.ts +43 -0
- package/backend/ws/containers/list.ts +146 -0
- package/backend/ws/containers/logs.ts +43 -0
- package/backend/ws/containers/tunnel.ts +101 -0
- package/backend/ws/git/log.ts +3 -1
- package/backend/ws/git/status.ts +37 -27
- package/backend/ws/index.ts +4 -0
- package/backend/ws/message-rate-limiter.test.ts +45 -0
- package/backend/ws/message-rate-limiter.ts +34 -3
- package/backend/ws/ports/index.ts +19 -0
- package/backend/ws/ports/kill.ts +80 -0
- package/backend/ws/ports/list.ts +60 -0
- package/backend/ws/ssh/connections.ts +8 -0
- package/backend/ws/system/device-info.ts +99 -43
- package/dist/assets/{index-BF4buYmI.js → index-B0iIhSO9.js} +1 -1
- package/dist/assets/{index-BW0DA8NV.js → index-BRJqss6F.js} +1 -1
- package/dist/assets/main-Buko4D0t.css +1 -0
- package/dist/assets/{main-BbwWLJRN.js → main-C_iGUZyL.js} +468 -447
- package/dist/index.html +2 -2
- package/dist/manifest.json +9 -2
- package/package.json +1 -1
- package/shared/types/containers/container.ts +366 -0
- package/shared/types/containers/index.ts +5 -0
- package/shared/types/host/index.ts +18 -0
- package/shared/types/ports/index.ts +5 -0
- package/shared/types/ports/port.ts +230 -0
- package/shared/utils/logger.ts +3 -0
- package/shared/utils/ws-client.ts +67 -12
- package/shared/utils/ws-server.ts +64 -13
- package/dist/assets/main-CCvRMXlP.css +0 -1
|
@@ -3,7 +3,15 @@ import { mkdtemp, rm, writeFile, mkdir } from 'node:fs/promises';
|
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { execGit } from './git-executor';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
beginWatchedDiscovery,
|
|
8
|
+
clearNestedRepoCache,
|
|
9
|
+
endWatchedDiscovery,
|
|
10
|
+
findNestedRepoPaths,
|
|
11
|
+
findRepoForFile,
|
|
12
|
+
invalidateRepoSet,
|
|
13
|
+
notifyPathChanged
|
|
14
|
+
} from './nested-repos';
|
|
7
15
|
|
|
8
16
|
/**
|
|
9
17
|
* Sub-repo detection used to walk the whole tree and report every directory
|
|
@@ -53,6 +61,10 @@ async function detected(): Promise<string[]> {
|
|
|
53
61
|
beforeEach(async () => {
|
|
54
62
|
root = await mkdtemp(path.join(tmpdir(), 'clopen-nested-'));
|
|
55
63
|
await initRepo(root);
|
|
64
|
+
// The walk is cached for seconds; these tests rebuild a project's layout in
|
|
65
|
+
// milliseconds. Without this a fixture would be asserted against the
|
|
66
|
+
// previous test's tree whenever mkdtemp hands back a reused path.
|
|
67
|
+
clearNestedRepoCache();
|
|
56
68
|
});
|
|
57
69
|
|
|
58
70
|
afterEach(async () => {
|
|
@@ -206,6 +218,285 @@ describe('findNestedRepoPaths', () => {
|
|
|
206
218
|
});
|
|
207
219
|
});
|
|
208
220
|
|
|
221
|
+
describe('walk cache', () => {
|
|
222
|
+
// The walk is the expensive half of discovery (readdir over the whole tree
|
|
223
|
+
// plus a `git check-ignore` spawn per level), and the Git panel fires it
|
|
224
|
+
// several times a second: staging triggers `git:status` and `git:branches`,
|
|
225
|
+
// and the `.git` watcher fires `git:changed` right behind them. On Windows
|
|
226
|
+
// each of those spawns is slow enough that the panel visibly froze.
|
|
227
|
+
|
|
228
|
+
test('reuses the walk instead of re-scanning the tree', async () => {
|
|
229
|
+
expect(await detected()).toEqual([]);
|
|
230
|
+
|
|
231
|
+
// Created after the walk was cached, so it must not be visible yet:
|
|
232
|
+
// this is what proves the second call did not re-scan.
|
|
233
|
+
await initRepo(path.join(root, 'packages/widget'));
|
|
234
|
+
expect(await detected()).toEqual([]);
|
|
235
|
+
|
|
236
|
+
clearNestedRepoCache();
|
|
237
|
+
expect(await detected()).toEqual(['packages/widget']);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
test('still reports a cached provisional repo the moment it gains work', async () => {
|
|
241
|
+
// The reason only the walk is cached. A repo inside an ignored tree is
|
|
242
|
+
// held back until it has something to show; if the filtered list were
|
|
243
|
+
// cached too, the sub-repo an agent just wrote into would stay missing
|
|
244
|
+
// from the Changes tab for the rest of the TTL.
|
|
245
|
+
await writeFile(path.join(root, '.gitignore'), 'themes/\n');
|
|
246
|
+
await initRepo(path.join(root, 'themes/mytheme'));
|
|
247
|
+
|
|
248
|
+
expect(await detected()).toEqual([]);
|
|
249
|
+
|
|
250
|
+
await addLocalWork(path.join(root, 'themes/mytheme'));
|
|
251
|
+
expect(await detected()).toEqual(['themes/mytheme']);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test('callers arriving during a walk share it and get their own array', async () => {
|
|
255
|
+
await initRepo(path.join(root, 'packages/widget'));
|
|
256
|
+
|
|
257
|
+
const [first, second] = await Promise.all([
|
|
258
|
+
findNestedRepoPaths(root),
|
|
259
|
+
findNestedRepoPaths(root)
|
|
260
|
+
]);
|
|
261
|
+
|
|
262
|
+
expect(second).toEqual(first);
|
|
263
|
+
// Separate arrays — `git:status` mutates the list it is handed, and it
|
|
264
|
+
// runs concurrently with `git:branches` on the same root.
|
|
265
|
+
expect(second).not.toBe(first);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test('scopes clearing to one root', async () => {
|
|
269
|
+
const other = await mkdtemp(path.join(tmpdir(), 'clopen-nested-other-'));
|
|
270
|
+
try {
|
|
271
|
+
await initRepo(other);
|
|
272
|
+
expect(await detected()).toEqual([]);
|
|
273
|
+
await findNestedRepoPaths(other);
|
|
274
|
+
|
|
275
|
+
await initRepo(path.join(root, 'packages/widget'));
|
|
276
|
+
await initRepo(path.join(other, 'packages/widget'));
|
|
277
|
+
|
|
278
|
+
clearNestedRepoCache(root);
|
|
279
|
+
expect(await detected()).toEqual(['packages/widget']);
|
|
280
|
+
expect(await findNestedRepoPaths(other)).toEqual([]);
|
|
281
|
+
} finally {
|
|
282
|
+
await rm(other, { recursive: true, force: true });
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
describe('watcher-driven discovery', () => {
|
|
288
|
+
// Discovery used to be re-derived on every `git:status` and `git:branches`:
|
|
289
|
+
// an `fs.readdir` over the whole tree, a `git check-ignore` spawn per repo
|
|
290
|
+
// per depth level, then a `git status` spawn per repo inside an ignored
|
|
291
|
+
// tree. The panel fires that three or four times a second while staging,
|
|
292
|
+
// and on Windows every spawn pays for Defender.
|
|
293
|
+
//
|
|
294
|
+
// The file watcher already knows when any of it changes, so it — not a
|
|
295
|
+
// clock — decides when an answer is stale. These tests pin the contract
|
|
296
|
+
// both ways: a watched root reuses answers, and every signal that could
|
|
297
|
+
// change one puts it back.
|
|
298
|
+
|
|
299
|
+
/** Count git subcommands spawned while `run` executes. */
|
|
300
|
+
async function countSpawns<T>(run: () => Promise<T>): Promise<{ result: T; spawns: string[] }> {
|
|
301
|
+
const spawns: string[] = [];
|
|
302
|
+
const realSpawn = Bun.spawn;
|
|
303
|
+
// argv is [git, -c, safe.directory=…, <subcommand>, …]
|
|
304
|
+
// @ts-expect-error test instrumentation
|
|
305
|
+
Bun.spawn = (cmd: string[], options: unknown) => {
|
|
306
|
+
if (Array.isArray(cmd) && cmd[3]) spawns.push(cmd[3]);
|
|
307
|
+
// @ts-expect-error passthrough
|
|
308
|
+
return realSpawn(cmd, options);
|
|
309
|
+
};
|
|
310
|
+
try {
|
|
311
|
+
return { result: await run(), spawns };
|
|
312
|
+
} finally {
|
|
313
|
+
Bun.spawn = realSpawn;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
test('a watched root answers a repeat call without touching git at all', async () => {
|
|
318
|
+
// The WordPress shape the detection policy was written for: every plugin
|
|
319
|
+
// is its own repo inside a tree the project ignores, so every one of them
|
|
320
|
+
// needs a `git status` to prove it has something to show. Unwatched, that
|
|
321
|
+
// is a spawn per plugin on every single call.
|
|
322
|
+
await writeFile(path.join(root, '.gitignore'), 'wp-content/plugins/\n');
|
|
323
|
+
for (const name of ['alpha', 'beta', 'gamma']) {
|
|
324
|
+
const plugin = path.join(root, 'wp-content/plugins', name);
|
|
325
|
+
await initRepo(plugin);
|
|
326
|
+
await addLocalWork(plugin);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
beginWatchedDiscovery(root);
|
|
330
|
+
expect(await detected()).toEqual([
|
|
331
|
+
'wp-content/plugins/alpha',
|
|
332
|
+
'wp-content/plugins/beta',
|
|
333
|
+
'wp-content/plugins/gamma'
|
|
334
|
+
]);
|
|
335
|
+
|
|
336
|
+
const { result, spawns } = await countSpawns(() => detected());
|
|
337
|
+
expect(result).toEqual([
|
|
338
|
+
'wp-content/plugins/alpha',
|
|
339
|
+
'wp-content/plugins/beta',
|
|
340
|
+
'wp-content/plugins/gamma'
|
|
341
|
+
]);
|
|
342
|
+
expect(spawns).toEqual([]);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
test('an unwatched root keeps probing live, so nothing can hide behind a guess', async () => {
|
|
346
|
+
// No watcher means no signal, and a cached "nothing to show" would hide a
|
|
347
|
+
// sub-repo the user is working in — the worst failure this module has.
|
|
348
|
+
await writeFile(path.join(root, '.gitignore'), 'themes/\n');
|
|
349
|
+
await initRepo(path.join(root, 'themes/mytheme'));
|
|
350
|
+
await addLocalWork(path.join(root, 'themes/mytheme'));
|
|
351
|
+
|
|
352
|
+
expect(await detected()).toEqual(['themes/mytheme']);
|
|
353
|
+
|
|
354
|
+
const { spawns } = await countSpawns(() => detected());
|
|
355
|
+
expect(spawns).toContain('status');
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
test('a write into a pristine sub-repo puts it back on the list', async () => {
|
|
359
|
+
// The transition the containment matching exists for. While `mytheme` is
|
|
360
|
+
// pristine it is deliberately unreported, so the watcher has never
|
|
361
|
+
// resolved a git dir for it and cannot name it. The only place it is
|
|
362
|
+
// known is the verdict cache holding the `false` that is about to be
|
|
363
|
+
// wrong — which is why invalidation matches by containment.
|
|
364
|
+
await writeFile(path.join(root, '.gitignore'), 'themes/\n');
|
|
365
|
+
await initRepo(path.join(root, 'themes/mytheme'));
|
|
366
|
+
|
|
367
|
+
beginWatchedDiscovery(root);
|
|
368
|
+
expect(await detected()).toEqual([]);
|
|
369
|
+
|
|
370
|
+
const edited = path.join(root, 'themes/mytheme/style.css');
|
|
371
|
+
await writeFile(edited, 'body { color: red }\n');
|
|
372
|
+
notifyPathChanged(root, edited);
|
|
373
|
+
|
|
374
|
+
expect(await detected()).toEqual(['themes/mytheme']);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
test('a sibling sub-repo keeps its verdict when one of them is written to', async () => {
|
|
378
|
+
await writeFile(path.join(root, '.gitignore'), 'themes/\n');
|
|
379
|
+
for (const name of ['alpha', 'beta']) {
|
|
380
|
+
const theme = path.join(root, 'themes', name);
|
|
381
|
+
await initRepo(theme);
|
|
382
|
+
await addLocalWork(theme);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
beginWatchedDiscovery(root);
|
|
386
|
+
expect(await detected()).toEqual(['themes/alpha', 'themes/beta']);
|
|
387
|
+
|
|
388
|
+
const edited = path.join(root, 'themes/alpha/style.css');
|
|
389
|
+
await writeFile(edited, 'body {}\n');
|
|
390
|
+
notifyPathChanged(root, edited);
|
|
391
|
+
|
|
392
|
+
// Only alpha is re-probed; beta answers from its cached verdict.
|
|
393
|
+
const { spawns } = await countSpawns(() => detected());
|
|
394
|
+
expect(spawns.filter((cmd) => cmd === 'status')).toHaveLength(1);
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
test('a per-repo exclude file moves the boundary like .gitignore does', async () => {
|
|
398
|
+
// `.git/info/exclude` is obeyed by `git check-ignore` exactly like
|
|
399
|
+
// `.gitignore`, so it decides whether a sub-repo has to prove local work.
|
|
400
|
+
// The watcher deliberately filters it out of the panel's git-state
|
|
401
|
+
// events — the panel has nothing to show for it — so discovery has to
|
|
402
|
+
// recognise it by name rather than ride along with those.
|
|
403
|
+
await initRepo(path.join(root, 'themes/mytheme'));
|
|
404
|
+
|
|
405
|
+
beginWatchedDiscovery(root);
|
|
406
|
+
expect(await detected()).toEqual(['themes/mytheme']);
|
|
407
|
+
|
|
408
|
+
await mkdir(path.join(root, '.git/info'), { recursive: true });
|
|
409
|
+
const exclude = path.join(root, '.git/info/exclude');
|
|
410
|
+
await writeFile(exclude, 'themes/\n');
|
|
411
|
+
notifyPathChanged(root, exclude);
|
|
412
|
+
|
|
413
|
+
// Now inside an ignored tree and pristine, so it drops off the list.
|
|
414
|
+
expect(await detected()).toEqual([]);
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
test('a .git appearing is itself a repo-set change', async () => {
|
|
418
|
+
beginWatchedDiscovery(root);
|
|
419
|
+
expect(await detected()).toEqual([]);
|
|
420
|
+
|
|
421
|
+
const widget = path.join(root, 'packages/widget');
|
|
422
|
+
await initRepo(widget);
|
|
423
|
+
notifyPathChanged(root, path.join(widget, '.git'));
|
|
424
|
+
|
|
425
|
+
expect(await detected()).toEqual(['packages/widget']);
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
test('an ordinary write is not treated as a repo-set change', async () => {
|
|
429
|
+
// The counterweight to the rules above: if every path invalidated the
|
|
430
|
+
// walk, the cache would do nothing at all during a build.
|
|
431
|
+
beginWatchedDiscovery(root);
|
|
432
|
+
expect(await detected()).toEqual([]);
|
|
433
|
+
|
|
434
|
+
await initRepo(path.join(root, 'packages/widget'));
|
|
435
|
+
const ordinary = path.join(root, 'src/app.ts');
|
|
436
|
+
await mkdir(path.join(root, 'src'), { recursive: true });
|
|
437
|
+
await writeFile(ordinary, 'export {}\n');
|
|
438
|
+
notifyPathChanged(root, ordinary);
|
|
439
|
+
|
|
440
|
+
expect(await detected()).toEqual([]);
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
test('ignores signals for a root nobody is watching', async () => {
|
|
444
|
+
await initRepo(path.join(root, 'packages/widget'));
|
|
445
|
+
// Never claimed, so there is no cached answer a signal could correct and
|
|
446
|
+
// nothing here should pretend otherwise.
|
|
447
|
+
notifyPathChanged(root, path.join(root, '.gitignore'));
|
|
448
|
+
expect(await detected()).toEqual(['packages/widget']);
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
test('two watchers on one root: the first to leave does not revoke the claim', async () => {
|
|
452
|
+
// Two projects can be opened at the same directory. Releasing on the
|
|
453
|
+
// first close would put discovery back on the clock while a perfectly
|
|
454
|
+
// good signal source was still running.
|
|
455
|
+
await writeFile(path.join(root, '.gitignore'), 'themes/\n');
|
|
456
|
+
await initRepo(path.join(root, 'themes/mytheme'));
|
|
457
|
+
await addLocalWork(path.join(root, 'themes/mytheme'));
|
|
458
|
+
|
|
459
|
+
beginWatchedDiscovery(root);
|
|
460
|
+
beginWatchedDiscovery(root);
|
|
461
|
+
expect(await detected()).toEqual(['themes/mytheme']);
|
|
462
|
+
|
|
463
|
+
endWatchedDiscovery(root);
|
|
464
|
+
const stillWatched = await countSpawns(() => detected());
|
|
465
|
+
expect(stillWatched.spawns).toEqual([]);
|
|
466
|
+
|
|
467
|
+
endWatchedDiscovery(root);
|
|
468
|
+
const released = await countSpawns(() => detected());
|
|
469
|
+
expect(released.spawns).toContain('status');
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
test('invalidating the repo set re-walks the tree', async () => {
|
|
473
|
+
beginWatchedDiscovery(root);
|
|
474
|
+
expect(await detected()).toEqual([]);
|
|
475
|
+
|
|
476
|
+
await initRepo(path.join(root, 'packages/widget'));
|
|
477
|
+
expect(await detected()).toEqual([]);
|
|
478
|
+
|
|
479
|
+
invalidateRepoSet(root);
|
|
480
|
+
expect(await detected()).toEqual(['packages/widget']);
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
test('losing the watcher drops every answer it was backing', async () => {
|
|
484
|
+
// Nothing will invalidate from here on, so a verdict kept across this
|
|
485
|
+
// boundary would never be corrected.
|
|
486
|
+
await writeFile(path.join(root, '.gitignore'), 'themes/\n');
|
|
487
|
+
await initRepo(path.join(root, 'themes/mytheme'));
|
|
488
|
+
await addLocalWork(path.join(root, 'themes/mytheme'));
|
|
489
|
+
|
|
490
|
+
beginWatchedDiscovery(root);
|
|
491
|
+
expect(await detected()).toEqual(['themes/mytheme']);
|
|
492
|
+
|
|
493
|
+
endWatchedDiscovery(root);
|
|
494
|
+
const { spawns } = await countSpawns(() => detected());
|
|
495
|
+
expect(spawns).toContain('check-ignore');
|
|
496
|
+
expect(spawns).toContain('status');
|
|
497
|
+
});
|
|
498
|
+
});
|
|
499
|
+
|
|
209
500
|
describe('findRepoForFile', () => {
|
|
210
501
|
test('routes a file to the deepest owning repo', async () => {
|
|
211
502
|
await initRepo(path.join(root, 'packages/widget'));
|