@myrialabs/clopen 0.4.34 → 0.4.36
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/artifacts/sync.test.ts +63 -0
- package/backend/artifacts/sync.ts +56 -3
- package/backend/auth/permissions.ts +7 -0
- 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/database/migrations/070_create_worktrees_table.ts +67 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/database/queries/index.ts +1 -0
- package/backend/database/queries/session-queries.ts +50 -11
- package/backend/database/queries/worktree-queries.ts +148 -0
- package/backend/engine/adapters/opencode/server.ts +389 -83
- package/backend/engine/adapters/opencode/stream.ts +14 -14
- package/backend/engine/hot-reload.ts +25 -10
- package/backend/files/file-watcher.test.ts +105 -0
- package/backend/files/file-watcher.ts +80 -10
- 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/metrics.test.ts +110 -0
- package/backend/host/metrics.ts +235 -0
- package/backend/{ports → host}/runner.ts +19 -10
- package/backend/index.ts +16 -4
- package/backend/mcp/internal/servers/browser-automation/context.ts +16 -2
- package/backend/ports/attribute.test.ts +3 -2
- package/backend/ports/attribute.ts +6 -45
- package/backend/ports/kill.ts +1 -1
- package/backend/ports/monitor.ts +1 -1
- package/backend/ports/processes.ts +1 -1
- package/backend/ports/scan-host.ts +77 -8
- package/backend/ports/scan.test.ts +1 -1
- package/backend/ports/scan.ts +1 -1
- package/backend/ports/ssh-lineage.ts +1 -1
- package/backend/preview/browser/browser-pool.ts +81 -0
- package/backend/preview/browser/browser-preview-service.ts +142 -32
- package/backend/preview/browser/browser-tab-manager.ts +350 -113
- package/backend/preview/browser/browser-video-capture.ts +84 -31
- package/backend/preview/browser/types.ts +9 -0
- package/backend/projects/project-cleanup.integration.test.ts +1 -1
- package/backend/projects/project-cleanup.ts +7 -1
- package/backend/projects/shell-ownership.ts +65 -0
- package/backend/snapshot/snapshot-service.ts +6 -2
- package/backend/terminal/ptykit.ts +35 -6
- package/backend/utils/ws.ts +21 -1
- package/backend/worktrees/clone.ts +222 -0
- package/backend/worktrees/index.ts +29 -0
- package/backend/worktrees/merge.test.ts +93 -0
- package/backend/worktrees/merge.ts +232 -0
- package/backend/worktrees/paths.test.ts +60 -0
- package/backend/worktrees/paths.ts +60 -0
- package/backend/worktrees/resolve.ts +67 -0
- package/backend/worktrees/service.ts +315 -0
- package/backend/worktrees/tree.ts +59 -0
- package/backend/ws/access.ts +18 -0
- package/backend/ws/artifacts/generate.ts +2 -2
- package/backend/ws/chat/stream.ts +9 -2
- 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/files/panel-state-scope.test.ts +102 -0
- package/backend/ws/files/path-access.test.ts +93 -1
- package/backend/ws/files/path-access.ts +54 -5
- package/backend/ws/files/read.ts +15 -10
- package/backend/ws/files/search.ts +7 -7
- package/backend/ws/files/state.ts +70 -8
- package/backend/ws/files/watch.ts +16 -14
- package/backend/ws/git/branch-name.ts +3 -3
- package/backend/ws/git/branch.ts +15 -15
- package/backend/ws/git/commit-message.ts +3 -3
- package/backend/ws/git/commit.ts +17 -17
- package/backend/ws/git/conflict.ts +10 -10
- package/backend/ws/git/diff.ts +9 -9
- package/backend/ws/git/ignored.ts +9 -9
- package/backend/ws/git/log.ts +6 -4
- package/backend/ws/git/remote.ts +43 -43
- package/backend/ws/git/staging.ts +16 -16
- package/backend/ws/git/status.ts +47 -37
- package/backend/ws/index.ts +6 -0
- package/backend/ws/message-rate-limiter.test.ts +45 -0
- package/backend/ws/message-rate-limiter.ts +34 -3
- package/backend/ws/preview/access.ts +11 -3
- package/backend/ws/projects/index.ts +5 -1
- package/backend/ws/projects/info.test.ts +54 -0
- package/backend/ws/projects/info.ts +398 -0
- package/backend/ws/sessions/crud.ts +21 -6
- package/backend/ws/snapshot/restore.ts +11 -14
- package/backend/ws/ssh/connections.ts +8 -0
- package/backend/ws/system/device-info.ts +70 -96
- package/backend/ws/worktrees/crud.ts +187 -0
- package/backend/ws/worktrees/index.ts +33 -0
- package/backend/ws/worktrees/transfer.ts +88 -0
- package/dist/assets/{index-vW2RpdHu.js → index-Bg-SUCFg.js} +1 -1
- package/dist/assets/{index-gGTMFUa8.js → index-Cz4YpHVi.js} +1 -1
- package/dist/assets/main-9G7IpQpK.css +1 -0
- package/dist/assets/main-BofFsH8E.js +1085 -0
- 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/database/schema.ts +26 -0
- package/shared/types/host/index.ts +18 -0
- package/shared/types/ports/port.ts +47 -9
- package/shared/utils/logger.ts +3 -0
- package/shared/utils/workspace-scope.test.ts +80 -0
- package/shared/utils/workspace-scope.ts +57 -0
- package/shared/utils/ws-client.ts +92 -17
- package/shared/utils/ws-server.ts +83 -16
- package/dist/assets/main-CYCMEbXB.css +0 -1
- package/dist/assets/main-ZCojSzvW.js +0 -1060
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import {
|
|
3
|
+
healthFrom,
|
|
4
|
+
linkUsage,
|
|
5
|
+
normaliseState,
|
|
6
|
+
parseDiskUsage,
|
|
7
|
+
parseDockerNetworks,
|
|
8
|
+
parseNetworkMembership,
|
|
9
|
+
parsePodmanNetworks,
|
|
10
|
+
parsePruneOutput,
|
|
11
|
+
parseStats,
|
|
12
|
+
parseDockerImages,
|
|
13
|
+
parseDockerPortsField,
|
|
14
|
+
parseDockerPs,
|
|
15
|
+
parseDockerVolumes,
|
|
16
|
+
parseInspect,
|
|
17
|
+
parseMounts,
|
|
18
|
+
parsePodmanImages,
|
|
19
|
+
parsePodmanPs,
|
|
20
|
+
parsePodmanVolumes,
|
|
21
|
+
parseTimestamp
|
|
22
|
+
} from './parse';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Fixtures are shaped like real runtime output but describe an invented host,
|
|
26
|
+
* so nothing about a contributor's own machine ends up in the repository.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
describe('parseTimestamp', () => {
|
|
30
|
+
test('reads Docker’s Go layout, dropping the zone abbreviation nothing can parse', () => {
|
|
31
|
+
expect(parseTimestamp('2026-08-25 09:02:11 +0700 WIB')).toBe('2026-08-25T02:02:11.000Z');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('reads RFC 3339 as Podman prints it', () => {
|
|
35
|
+
expect(parseTimestamp('2026-08-25T09:02:11.123456789+07:00')).toBe('2026-08-25T02:02:11.123Z');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('reads a Unix epoch in seconds and in milliseconds', () => {
|
|
39
|
+
expect(parseTimestamp(1787_000_000)).toBe(new Date(1787_000_000_000).toISOString());
|
|
40
|
+
expect(parseTimestamp(1787_000_000_000)).toBe(new Date(1787_000_000_000).toISOString());
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('reports nothing rather than a wrong date', () => {
|
|
44
|
+
expect(parseTimestamp('mar. août 25 09:02:11 2026')).toBeNull();
|
|
45
|
+
expect(parseTimestamp('')).toBeNull();
|
|
46
|
+
expect(parseTimestamp(null)).toBeNull();
|
|
47
|
+
// Go's zero time, which both runtimes print for a container never started.
|
|
48
|
+
expect(parseTimestamp('0001-01-01T00:00:00Z')).toBeNull();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('normaliseState', () => {
|
|
53
|
+
test('takes the runtime’s own word when there is one', () => {
|
|
54
|
+
expect(normaliseState('running', '')).toBe('running');
|
|
55
|
+
expect(normaliseState('exited', '')).toBe('exited');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('translates Podman’s vocabulary', () => {
|
|
59
|
+
expect(normaliseState('stopped', '')).toBe('exited');
|
|
60
|
+
expect(normaliseState('configured', '')).toBe('created');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('falls back to the status text, for a Docker too old to have a State column', () => {
|
|
64
|
+
expect(normaliseState(null, 'Up 3 hours (healthy)')).toBe('running');
|
|
65
|
+
expect(normaliseState(null, 'Up 2 days (Paused)')).toBe('paused');
|
|
66
|
+
expect(normaliseState(null, 'Exited (0) 4 minutes ago')).toBe('exited');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('says unknown rather than guessing', () => {
|
|
70
|
+
expect(normaliseState('teleporting', 'something else')).toBe('unknown');
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('healthFrom', () => {
|
|
75
|
+
test('reads the verdict out of the status text', () => {
|
|
76
|
+
expect(healthFrom('Up 3 hours (healthy)')).toBe('healthy');
|
|
77
|
+
expect(healthFrom('Up 3 hours (unhealthy)')).toBe('unhealthy');
|
|
78
|
+
expect(healthFrom('Up 8 seconds (health: starting)')).toBe('starting');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('prefers an explicit field when the runtime provides one', () => {
|
|
82
|
+
expect(healthFrom(null, 'unhealthy')).toBe('unhealthy');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('says none when the image declares no healthcheck', () => {
|
|
86
|
+
expect(healthFrom('Up 3 hours')).toBe('none');
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('parseDockerPortsField', () => {
|
|
91
|
+
test('reads a published mapping', () => {
|
|
92
|
+
expect(parseDockerPortsField('0.0.0.0:8080->80/tcp')).toEqual([
|
|
93
|
+
{ hostAddress: '0.0.0.0', hostPort: 8080, containerPort: 80, protocol: 'tcp' }
|
|
94
|
+
]);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('folds the IPv6 twin of a mapping into one binding', () => {
|
|
98
|
+
const bindings = parseDockerPortsField('0.0.0.0:8080->80/tcp, :::8080->80/tcp');
|
|
99
|
+
expect(bindings).toHaveLength(1);
|
|
100
|
+
expect(bindings[0].hostAddress).toBe('0.0.0.0');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('expands a published range so no reachable port is hidden', () => {
|
|
104
|
+
const bindings = parseDockerPortsField('0.0.0.0:8000-8002->8000-8002/tcp');
|
|
105
|
+
expect(bindings.map((binding) => binding.hostPort)).toEqual([8000, 8001, 8002]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('keeps a port exposed but not published, with no host port', () => {
|
|
109
|
+
expect(parseDockerPortsField('9000/tcp')).toEqual([
|
|
110
|
+
{ hostAddress: null, hostPort: null, containerPort: 9000, protocol: 'tcp' }
|
|
111
|
+
]);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('reads udp and a loopback-only binding', () => {
|
|
115
|
+
expect(parseDockerPortsField('127.0.0.1:5353->53/udp')).toEqual([
|
|
116
|
+
{ hostAddress: '127.0.0.1', hostPort: 5353, containerPort: 53, protocol: 'udp' }
|
|
117
|
+
]);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test('reports nothing for an empty column', () => {
|
|
121
|
+
expect(parseDockerPortsField('')).toEqual([]);
|
|
122
|
+
expect(parseDockerPortsField(null)).toEqual([]);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe('parseDockerPs', () => {
|
|
127
|
+
const output = [
|
|
128
|
+
JSON.stringify({
|
|
129
|
+
ID: 'a1b2c3d4e5f60718293a4b5c6d7e8f9012345678901234567890abcdefabcdef',
|
|
130
|
+
Names: 'shop-api-1',
|
|
131
|
+
Image: 'shop/api:2.1',
|
|
132
|
+
State: 'running',
|
|
133
|
+
Status: 'Up 3 hours (healthy)',
|
|
134
|
+
Ports: '0.0.0.0:8080->80/tcp, :::8080->80/tcp',
|
|
135
|
+
CreatedAt: '2026-08-25 09:02:11 +0700 WIB',
|
|
136
|
+
Labels: 'com.docker.compose.project=shop,com.docker.compose.service=api',
|
|
137
|
+
Command: '"nginx -g daemon off;"',
|
|
138
|
+
Mounts: 'shop-assets'
|
|
139
|
+
}),
|
|
140
|
+
JSON.stringify({
|
|
141
|
+
ID: 'bb22cc33dd44ee55ff6600112233445566778899aabbccddeeff001122334455',
|
|
142
|
+
Names: 'shop-db-1',
|
|
143
|
+
Image: 'postgres:16',
|
|
144
|
+
State: 'exited',
|
|
145
|
+
Status: 'Exited (0) 4 minutes ago',
|
|
146
|
+
Ports: '',
|
|
147
|
+
CreatedAt: '2026-08-24 18:40:00 +0700 WIB',
|
|
148
|
+
Labels: 'com.docker.compose.project=shop,com.docker.compose.service=db',
|
|
149
|
+
Command: '"postgres"',
|
|
150
|
+
Mounts: 'shop-data'
|
|
151
|
+
}),
|
|
152
|
+
'a warning the daemon printed on its way out',
|
|
153
|
+
''
|
|
154
|
+
].join('\n');
|
|
155
|
+
|
|
156
|
+
const entries = parseDockerPs(output, 'local');
|
|
157
|
+
|
|
158
|
+
test('reads every container and ignores anything that is not a row', () => {
|
|
159
|
+
expect(entries).toHaveLength(2);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('keys the row by host and id, so two hosts never collide', () => {
|
|
163
|
+
expect(entries[0].key).toBe(`local:${entries[0].id}`);
|
|
164
|
+
expect(entries[0].shortId).toBe('a1b2c3d4e5f6');
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('reads state, health and the compose labels', () => {
|
|
168
|
+
expect(entries[0]).toMatchObject({
|
|
169
|
+
name: 'shop-api-1',
|
|
170
|
+
image: 'shop/api:2.1',
|
|
171
|
+
state: 'running',
|
|
172
|
+
health: 'healthy',
|
|
173
|
+
composeProject: 'shop',
|
|
174
|
+
composeService: 'api'
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('reads the published port, folded across address families', () => {
|
|
179
|
+
expect(entries[0].ports).toEqual([
|
|
180
|
+
{ hostAddress: '0.0.0.0', hostPort: 8080, containerPort: 80, protocol: 'tcp' }
|
|
181
|
+
]);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('leaves a stopped container with no start time rather than inventing one', () => {
|
|
185
|
+
expect(entries[1]).toMatchObject({ state: 'exited', startedAt: null, ports: [] });
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe('parsePodmanPs', () => {
|
|
190
|
+
const output = JSON.stringify([
|
|
191
|
+
{
|
|
192
|
+
Id: 'cc33dd44ee55ff6600112233445566778899aabbccddeeff00112233445566aa',
|
|
193
|
+
Names: ['shop-api'],
|
|
194
|
+
Image: 'docker.io/shop/api:2.1',
|
|
195
|
+
State: 'running',
|
|
196
|
+
Status: '',
|
|
197
|
+
StartedAt: 1787_000_000,
|
|
198
|
+
Created: '2026-08-25T09:02:11.123456789+07:00',
|
|
199
|
+
Command: ['nginx', '-g', 'daemon off;'],
|
|
200
|
+
Labels: { 'com.docker.compose.project': 'shop', 'com.docker.compose.service': 'api' },
|
|
201
|
+
Ports: [{ host_ip: '0.0.0.0', container_port: 80, host_port: 8080, range: 1, protocol: 'tcp' }],
|
|
202
|
+
Mounts: ['shop-assets'],
|
|
203
|
+
IsInfra: false
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
Id: 'dd44ee55ff6600112233445566778899aabbccddeeff00112233445566aabbcc',
|
|
207
|
+
Names: ['shop-pod-infra'],
|
|
208
|
+
Image: 'localhost/podman-pause:5.0',
|
|
209
|
+
State: 'running',
|
|
210
|
+
IsInfra: true
|
|
211
|
+
}
|
|
212
|
+
]);
|
|
213
|
+
|
|
214
|
+
const entries = parsePodmanPs(output, 'vps-1');
|
|
215
|
+
|
|
216
|
+
test('drops the pod infra container, which is plumbing rather than a workload', () => {
|
|
217
|
+
expect(entries).toHaveLength(1);
|
|
218
|
+
expect(entries[0].name).toBe('shop-api');
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test('joins the argv Podman reports as an array', () => {
|
|
222
|
+
expect(entries[0].command).toBe('nginx -g daemon off;');
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test('reads structured ports', () => {
|
|
226
|
+
expect(entries[0].ports).toEqual([
|
|
227
|
+
{ hostAddress: '0.0.0.0', hostPort: 8080, containerPort: 80, protocol: 'tcp' }
|
|
228
|
+
]);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test('writes a status line when Podman leaves the field empty', () => {
|
|
232
|
+
expect(entries[0].statusText.startsWith('Up ')).toBe(true);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test('expands Podman’s port range shorthand', () => {
|
|
236
|
+
const ranged = parsePodmanPs(
|
|
237
|
+
JSON.stringify([
|
|
238
|
+
{
|
|
239
|
+
Id: 'ee55ff6600112233445566778899aabbccddeeff00112233445566aabbccdd11',
|
|
240
|
+
Names: ['range-demo'],
|
|
241
|
+
Image: 'demo',
|
|
242
|
+
State: 'running',
|
|
243
|
+
Ports: [{ host_ip: '', container_port: 8000, host_port: 8000, range: 3, protocol: 'tcp' }]
|
|
244
|
+
}
|
|
245
|
+
]),
|
|
246
|
+
'vps-1'
|
|
247
|
+
);
|
|
248
|
+
expect(ranged[0].ports.map((port) => port.hostPort)).toEqual([8000, 8001, 8002]);
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
describe('images and volumes', () => {
|
|
253
|
+
test('reads Docker’s image rows and marks the danglers', () => {
|
|
254
|
+
const images = parseDockerImages(
|
|
255
|
+
[
|
|
256
|
+
JSON.stringify({
|
|
257
|
+
ID: 'sha256:aaa111',
|
|
258
|
+
Repository: 'shop/api',
|
|
259
|
+
Tag: '2.1',
|
|
260
|
+
Size: '184MB',
|
|
261
|
+
CreatedAt: '2026-08-20 11:00:00 +0700 WIB'
|
|
262
|
+
}),
|
|
263
|
+
JSON.stringify({ ID: 'sha256:bbb222', Repository: '<none>', Tag: '<none>', Size: '92MB' })
|
|
264
|
+
].join('\n')
|
|
265
|
+
);
|
|
266
|
+
expect(images).toHaveLength(2);
|
|
267
|
+
expect(images[0]).toMatchObject({ repository: 'shop/api', tag: '2.1', dangling: false });
|
|
268
|
+
expect(images[1].dangling).toBe(true);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
test('splits Podman’s fully qualified names into repository and tag', () => {
|
|
272
|
+
const images = parsePodmanImages(
|
|
273
|
+
JSON.stringify([
|
|
274
|
+
{ Id: 'aaa111', Names: ['docker.io/shop/api:2.1'], Size: 184_000_000, Created: 1787_000_000 },
|
|
275
|
+
{ Id: 'ccc333', Names: ['localhost:5000/internal/tool'], Size: 1_000 }
|
|
276
|
+
])
|
|
277
|
+
);
|
|
278
|
+
expect(images[0]).toMatchObject({ repository: 'docker.io/shop/api', tag: '2.1', size: '184MB' });
|
|
279
|
+
// A registry port is not a tag: `localhost:5000/internal/tool` has none.
|
|
280
|
+
expect(images[1]).toMatchObject({ repository: 'localhost:5000/internal/tool', tag: 'latest' });
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
test('reads volumes from either runtime', () => {
|
|
284
|
+
expect(
|
|
285
|
+
parseDockerVolumes(JSON.stringify({ Name: 'shop-data', Driver: 'local', Mountpoint: '/var/lib/docker/volumes/shop-data/_data' }))
|
|
286
|
+
).toEqual([
|
|
287
|
+
{
|
|
288
|
+
key: 'shop-data',
|
|
289
|
+
name: 'shop-data',
|
|
290
|
+
driver: 'local',
|
|
291
|
+
mountpoint: '/var/lib/docker/volumes/shop-data/_data',
|
|
292
|
+
createdAt: null,
|
|
293
|
+
usedBy: []
|
|
294
|
+
}
|
|
295
|
+
]);
|
|
296
|
+
|
|
297
|
+
expect(
|
|
298
|
+
parsePodmanVolumes(
|
|
299
|
+
JSON.stringify([{ Name: 'shop-data', Driver: 'local', Mountpoint: '/home/deploy/.local/share/containers/storage/volumes/shop-data/_data', CreatedAt: '2026-08-01T10:00:00Z' }])
|
|
300
|
+
)[0]
|
|
301
|
+
).toMatchObject({ name: 'shop-data', createdAt: '2026-08-01T10:00:00.000Z' });
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
describe('linkUsage', () => {
|
|
306
|
+
test('names the containers using each image and volume', () => {
|
|
307
|
+
const listing = JSON.stringify({
|
|
308
|
+
ID: 'a1b2c3d4e5f60718293a4b5c6d7e8f9012345678901234567890abcdefabcdef',
|
|
309
|
+
Names: 'shop-api-1',
|
|
310
|
+
Image: 'shop/api:2.1',
|
|
311
|
+
State: 'running',
|
|
312
|
+
Status: 'Up 3 hours',
|
|
313
|
+
Mounts: 'shop-assets,shop-data'
|
|
314
|
+
});
|
|
315
|
+
const entries = parseDockerPs(listing, 'local');
|
|
316
|
+
const images = parseDockerImages(
|
|
317
|
+
JSON.stringify({ ID: 'sha256:aaa111', Repository: 'shop/api', Tag: '2.1', Size: '184MB' })
|
|
318
|
+
);
|
|
319
|
+
const volumes = parseDockerVolumes(
|
|
320
|
+
[
|
|
321
|
+
JSON.stringify({ Name: 'shop-assets', Driver: 'local' }),
|
|
322
|
+
JSON.stringify({ Name: 'orphan-cache', Driver: 'local' })
|
|
323
|
+
].join('\n')
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
linkUsage(entries, images, volumes, parseMounts(listing, 'docker'));
|
|
327
|
+
|
|
328
|
+
expect(images[0].usedBy).toEqual(['shop-api-1']);
|
|
329
|
+
expect(volumes[0].usedBy).toEqual(['shop-api-1']);
|
|
330
|
+
expect(volumes[1].usedBy).toEqual([]);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
test('matches a Podman image name against a container’s fully qualified one', () => {
|
|
334
|
+
const entries = parsePodmanPs(
|
|
335
|
+
JSON.stringify([
|
|
336
|
+
{
|
|
337
|
+
Id: 'cc33dd44ee55ff6600112233445566778899aabbccddeeff00112233445566aa',
|
|
338
|
+
Names: ['shop-api'],
|
|
339
|
+
Image: 'docker.io/shop/api:2.1',
|
|
340
|
+
State: 'running'
|
|
341
|
+
}
|
|
342
|
+
]),
|
|
343
|
+
'vps-1'
|
|
344
|
+
);
|
|
345
|
+
const images = parsePodmanImages(
|
|
346
|
+
JSON.stringify([{ Id: 'aaa111', Names: ['shop/api:2.1'], Size: 1000 }])
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
linkUsage(entries, images, [], new Map());
|
|
350
|
+
expect(images[0].usedBy).toEqual(['shop-api']);
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
describe('parseInspect', () => {
|
|
355
|
+
const output = JSON.stringify({
|
|
356
|
+
Id: 'a1b2c3d4e5f60718293a4b5c6d7e8f9012345678901234567890abcdefabcdef',
|
|
357
|
+
Name: '/shop-api-1',
|
|
358
|
+
Created: '2026-08-25T02:02:11.000Z',
|
|
359
|
+
Image: 'sha256:aaa111',
|
|
360
|
+
RestartCount: 2,
|
|
361
|
+
Path: '/docker-entrypoint.sh',
|
|
362
|
+
State: {
|
|
363
|
+
Status: 'running',
|
|
364
|
+
Running: true,
|
|
365
|
+
StartedAt: '2026-08-25T02:02:12.000Z',
|
|
366
|
+
FinishedAt: '0001-01-01T00:00:00Z',
|
|
367
|
+
ExitCode: 0,
|
|
368
|
+
Pid: 4210,
|
|
369
|
+
Health: { Status: 'healthy' }
|
|
370
|
+
},
|
|
371
|
+
Config: {
|
|
372
|
+
Image: 'shop/api:2.1',
|
|
373
|
+
Cmd: ['nginx', '-g', 'daemon off;'],
|
|
374
|
+
Env: ['NODE_ENV=production'],
|
|
375
|
+
WorkingDir: '/srv/app',
|
|
376
|
+
User: 'app',
|
|
377
|
+
Labels: { 'com.docker.compose.project': 'shop' }
|
|
378
|
+
},
|
|
379
|
+
HostConfig: { RestartPolicy: { Name: 'unless-stopped' } },
|
|
380
|
+
NetworkSettings: {
|
|
381
|
+
Networks: { shop_default: { IPAddress: '172.19.0.4' } },
|
|
382
|
+
Ports: {
|
|
383
|
+
'80/tcp': [
|
|
384
|
+
{ HostIp: '0.0.0.0', HostPort: '8080' },
|
|
385
|
+
{ HostIp: '::', HostPort: '8080' }
|
|
386
|
+
],
|
|
387
|
+
'9000/tcp': null
|
|
388
|
+
}
|
|
389
|
+
},
|
|
390
|
+
Mounts: [{ Type: 'volume', Name: 'shop-assets', Source: '/var/lib/docker/volumes/shop-assets/_data', Destination: '/srv/app/public', RW: true }]
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
const detail = parseInspect(output);
|
|
394
|
+
|
|
395
|
+
test('reads the container, with the slash Docker prefixes its name with removed', () => {
|
|
396
|
+
expect(detail?.name).toBe('shop-api-1');
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
test('reads state, health, pid and restart policy', () => {
|
|
400
|
+
expect(detail).toMatchObject({
|
|
401
|
+
state: 'running',
|
|
402
|
+
health: 'healthy',
|
|
403
|
+
pid: 4210,
|
|
404
|
+
restartCount: 2,
|
|
405
|
+
restartPolicy: 'unless-stopped',
|
|
406
|
+
workingDir: '/srv/app',
|
|
407
|
+
user: 'app'
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
test('reports Go’s zero time as no finish time at all', () => {
|
|
412
|
+
expect(detail?.finishedAt).toBeNull();
|
|
413
|
+
expect(detail?.startedAt).toBe('2026-08-25T02:02:12.000Z');
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
test('reads published and merely exposed ports, folding the address families', () => {
|
|
417
|
+
expect(detail?.ports).toEqual([
|
|
418
|
+
{ hostAddress: '0.0.0.0', hostPort: 8080, containerPort: 80, protocol: 'tcp' },
|
|
419
|
+
{ hostAddress: null, hostPort: null, containerPort: 9000, protocol: 'tcp' }
|
|
420
|
+
]);
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
test('reads networks and mounts', () => {
|
|
424
|
+
expect(detail?.networks).toEqual([{ name: 'shop_default', ipAddress: '172.19.0.4' }]);
|
|
425
|
+
expect(detail?.mounts[0]).toMatchObject({
|
|
426
|
+
destination: '/srv/app/public',
|
|
427
|
+
readOnly: false,
|
|
428
|
+
kind: 'volume'
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
test('reports nothing for output that names no container', () => {
|
|
433
|
+
expect(parseInspect('')).toBeNull();
|
|
434
|
+
expect(parseInspect('[]')).toBeNull();
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
describe('networks', () => {
|
|
439
|
+
test('reads Docker’s network rows and marks the runtime’s own', () => {
|
|
440
|
+
const networks = parseDockerNetworks(
|
|
441
|
+
[
|
|
442
|
+
JSON.stringify({
|
|
443
|
+
ID: '52048fed8d9d867057ed8a5f05cfad27ac99835640e621b2b844aba0292d21a0',
|
|
444
|
+
Name: 'shop_default',
|
|
445
|
+
Driver: 'bridge',
|
|
446
|
+
Scope: 'local',
|
|
447
|
+
Internal: 'false',
|
|
448
|
+
CreatedAt: '2026-05-15 15:40:00.397 +0700 WIB'
|
|
449
|
+
}),
|
|
450
|
+
JSON.stringify({ ID: '5f57c31f263f', Name: 'bridge', Driver: 'bridge', Scope: 'local' })
|
|
451
|
+
].join('\n')
|
|
452
|
+
);
|
|
453
|
+
|
|
454
|
+
expect(networks[0]).toMatchObject({
|
|
455
|
+
name: 'shop_default',
|
|
456
|
+
driver: 'bridge',
|
|
457
|
+
internal: false,
|
|
458
|
+
predefined: false
|
|
459
|
+
});
|
|
460
|
+
// `bridge` cannot be removed on any host, so it is never offered as such.
|
|
461
|
+
expect(networks[1].predefined).toBe(true);
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
test('reads Podman’s lower-case field names', () => {
|
|
465
|
+
const networks = parsePodmanNetworks(
|
|
466
|
+
JSON.stringify([
|
|
467
|
+
{ name: 'shop_default', id: 'aa11bb22', driver: 'bridge', created: '2026-05-15T15:40:00Z' },
|
|
468
|
+
{ name: 'podman', id: 'cc33dd44', driver: 'bridge' }
|
|
469
|
+
])
|
|
470
|
+
);
|
|
471
|
+
expect(networks[0]).toMatchObject({ name: 'shop_default', id: 'aa11bb22', predefined: false });
|
|
472
|
+
expect(networks[1].predefined).toBe(true);
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
test('names the containers attached to each network', () => {
|
|
476
|
+
const listing = JSON.stringify({
|
|
477
|
+
ID: 'a1b2c3d4e5f60718293a4b5c6d7e8f9012345678901234567890abcdefabcdef',
|
|
478
|
+
Names: 'shop-api-1',
|
|
479
|
+
Image: 'shop/api:2.1',
|
|
480
|
+
State: 'running',
|
|
481
|
+
Status: 'Up 3 hours',
|
|
482
|
+
Networks: 'shop_default'
|
|
483
|
+
});
|
|
484
|
+
const entries = parseDockerPs(listing, 'local');
|
|
485
|
+
const networks = parseDockerNetworks(
|
|
486
|
+
[
|
|
487
|
+
JSON.stringify({ ID: 'aa11', Name: 'shop_default', Driver: 'bridge' }),
|
|
488
|
+
JSON.stringify({ ID: 'bb22', Name: 'orphan_net', Driver: 'bridge' })
|
|
489
|
+
].join('\n')
|
|
490
|
+
);
|
|
491
|
+
|
|
492
|
+
linkUsage(entries, [], [], new Map(), networks, parseNetworkMembership(listing, 'docker'));
|
|
493
|
+
|
|
494
|
+
expect(networks[0].usedBy).toEqual(['shop-api-1']);
|
|
495
|
+
expect(networks[1].usedBy).toEqual([]);
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
describe('parsePruneOutput', () => {
|
|
500
|
+
test('reads what Docker removed and the space it freed', () => {
|
|
501
|
+
const output = [
|
|
502
|
+
'Deleted Volumes:',
|
|
503
|
+
'shop-cache',
|
|
504
|
+
'a78f6fd7e8b9d8bd121d1e36bb05900293bd4c6f30f9a3565b2bf96c3294fced',
|
|
505
|
+
'',
|
|
506
|
+
'Total reclaimed space: 1.24GB'
|
|
507
|
+
].join('\n');
|
|
508
|
+
expect(parsePruneOutput(output)).toEqual({ removed: 2, reclaimed: '1.24GB' });
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
test('does not count an untag as a deletion', () => {
|
|
512
|
+
// `image prune` lists the tag it dropped beside the layer it deleted;
|
|
513
|
+
// counting both would report twice as much work as it did.
|
|
514
|
+
const output = [
|
|
515
|
+
'Deleted Images:',
|
|
516
|
+
'untagged: shop/api:2.1',
|
|
517
|
+
'deleted: sha256:aaa111',
|
|
518
|
+
'',
|
|
519
|
+
'Total reclaimed space: 184MB'
|
|
520
|
+
].join('\n');
|
|
521
|
+
expect(parsePruneOutput(output)).toEqual({ removed: 1, reclaimed: '184MB' });
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
test('reports no space rather than a made-up figure when the runtime is silent', () => {
|
|
525
|
+
// Podman prints the ids it removed and nothing else.
|
|
526
|
+
expect(parsePruneOutput('aa11bb22\ncc33dd44\n')).toEqual({ removed: 2, reclaimed: null });
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
test('reads a sweep that found nothing', () => {
|
|
530
|
+
expect(parsePruneOutput('Total reclaimed space: 0B\n')).toEqual({
|
|
531
|
+
removed: 0,
|
|
532
|
+
reclaimed: '0B'
|
|
533
|
+
});
|
|
534
|
+
});
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
describe('parseDiskUsage', () => {
|
|
538
|
+
test('reads Docker’s four resource lines', () => {
|
|
539
|
+
const usage = parseDiskUsage(
|
|
540
|
+
[
|
|
541
|
+
JSON.stringify({ Type: 'Images', TotalCount: '66', Active: '19', Size: '32.91GB', Reclaimable: '12.27GB (37%)' }),
|
|
542
|
+
JSON.stringify({ Type: 'Containers', TotalCount: '23', Active: '9', Size: '840.6MB', Reclaimable: '702MB (83%)' }),
|
|
543
|
+
JSON.stringify({ Type: 'Local Volumes', TotalCount: '327', Active: '13', Size: '25.16GB', Reclaimable: '24.47GB (97%)' }),
|
|
544
|
+
JSON.stringify({ Type: 'Build Cache', TotalCount: '38', Active: '0', Size: '1.969GB', Reclaimable: '1.24GB' })
|
|
545
|
+
].join('\n'),
|
|
546
|
+
'docker'
|
|
547
|
+
);
|
|
548
|
+
|
|
549
|
+
expect(usage.rows.map((row) => row.kind)).toEqual([
|
|
550
|
+
'images',
|
|
551
|
+
'containers',
|
|
552
|
+
'volumes',
|
|
553
|
+
'build-cache'
|
|
554
|
+
]);
|
|
555
|
+
expect(usage.rows[2]).toMatchObject({ total: 327, active: 13, reclaimable: '24.47GB (97%)' });
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
test('formats Podman’s raw byte counts', () => {
|
|
559
|
+
const usage = parseDiskUsage(
|
|
560
|
+
JSON.stringify([{ Type: 'Images', Total: 5, Active: 2, Size: 184_000_000, Reclaimable: 92_000_000 }]),
|
|
561
|
+
'podman'
|
|
562
|
+
);
|
|
563
|
+
expect(usage.rows[0]).toMatchObject({ kind: 'images', size: '184MB', reclaimable: '92MB' });
|
|
564
|
+
});
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
describe('parseStats', () => {
|
|
568
|
+
test('reads a Docker sample', () => {
|
|
569
|
+
const stats = parseStats(
|
|
570
|
+
JSON.stringify({
|
|
571
|
+
BlockIO: '17MB / 120MB',
|
|
572
|
+
CPUPerc: '0.05%',
|
|
573
|
+
MemPerc: '1.84%',
|
|
574
|
+
MemUsage: '36.12MiB / 1.913GiB',
|
|
575
|
+
NetIO: '878kB / 2.18MB',
|
|
576
|
+
PIDs: '6'
|
|
577
|
+
})
|
|
578
|
+
);
|
|
579
|
+
expect(stats).toEqual({
|
|
580
|
+
cpuPercent: 0.05,
|
|
581
|
+
memoryUsage: '36.12MiB / 1.913GiB',
|
|
582
|
+
memoryPercent: 1.84,
|
|
583
|
+
networkIO: '878kB / 2.18MB',
|
|
584
|
+
blockIO: '17MB / 120MB',
|
|
585
|
+
pids: 6
|
|
586
|
+
});
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
test('joins the usage and limit Podman reports separately', () => {
|
|
590
|
+
const stats = parseStats(
|
|
591
|
+
JSON.stringify([{ cpu_percent: '1.20%', mem_usage: '36MB', MemLimit: '2GB', pids: 6 }])
|
|
592
|
+
);
|
|
593
|
+
expect(stats).toMatchObject({ cpuPercent: 1.2, memoryUsage: '36MB / 2GB', pids: 6 });
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
test('reports nothing for a container that gave no sample', () => {
|
|
597
|
+
expect(parseStats('')).toBeNull();
|
|
598
|
+
});
|
|
599
|
+
});
|