Skip to content

Commit 299fc3a

Browse files
committed
feat: Fixes testing harness for linux. Fix syncthing for linux
1 parent d8820c8 commit 299fc3a

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

scripts/run-tests.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ async function launchPersistentTest(test: string, debug: boolean, operatingSyste
9898

9999
console.log('Done refreshing files on VM. Starting tests...');
100100
VerbosityLevel.set(3);
101-
await codifySpawn(`tart exec -i ${vmName} ${shell} -c -i "cd ${dir} && FORCE_COLOR=true npm run test -- ${test} --disable-console-intercept ${debugFlag} --no-file-parallelism"`, { throws: false });
101+
await codifySpawn(`tart exec -i ${vmName} ${shell} -c -i 'cd ${dir} && XDG_RUNTIME_DIR="/run/user/$(id -u)" DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus" FORCE_COLOR=true npm run test -- ${test} --disable-console-intercept ${debugFlag} --no-file-parallelism'`, { throws: false });
102102
// }
103103
}
104104

@@ -128,7 +128,17 @@ async function launchPersistentVm(operatingSystem: string) {
128128
} else {
129129
await testSpawn(`tart exec ${newVmName} ${shell} -i -c "curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash"`)
130130
await testSpawn(`tart exec ${newVmName} ${shell} -i -c "nvm install 24; nvm alias default 24"`)
131+
132+
// XDG_RUNTIME_DIR is required by systemd user services (e.g. `systemctl --user`). On desktop
133+
// Linux it is set automatically by PAM/logind on graphical login, but non-interactive SSH/tart
134+
// sessions skip that path, so we set it explicitly to the canonical location /run/user/<uid>.
131135
await testSpawn(`tart exec ${newVmName} ${shell} -i -c "echo 'export XDG_RUNTIME_DIR=/run/user/$(id -u)' >> ~/.bashrc"`)
136+
137+
// enable-linger keeps the user's systemd session alive after logout. Without it, user-scoped
138+
// systemd units (like syncthing.service) are stopped when the tart session ends, which causes
139+
// `systemctl --user enable --now` to fail during integration tests.
140+
await testSpawn(`tart exec ${newVmName} ${shell} -i -c "loginctl enable-linger admin"`)
141+
132142
}
133143

134144
await testSpawn(`tart exec ${newVmName} ${shell} -i -c "cd ~/codify-homebrew-plugin && npm ci"`);

src/resources/syncthing/syncthing.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,17 @@ export class SyncthingResource extends Resource<SyncthingConfig> {
237237
const $ = getPty();
238238

239239
// Add the official Syncthing apt repository
240-
await $.spawn('sudo mkdir -p /etc/apt/keyrings', { interactive: true });
240+
await $.spawn('mkdir -p /etc/apt/keyrings', { interactive: true, requiresRoot: true });
241241
await $.spawn(
242-
'sudo curl -L -o /etc/apt/keyrings/syncthing-archive-keyring.gpg https://syncthing.net/release-key.gpg',
243-
{ interactive: true }
242+
'curl -L -o /etc/apt/keyrings/syncthing-archive-keyring.gpg https://syncthing.net/release-key.gpg',
243+
{ interactive: true, requiresRoot: true }
244244
);
245245
await $.spawn(
246-
'echo "deb [signed-by=/etc/apt/keyrings/syncthing-archive-keyring.gpg] https://apt.syncthing.net/ syncthing stable" | sudo tee /etc/apt/sources.list.d/syncthing.list',
247-
{ interactive: true }
246+
'bash -c \'echo "deb [signed-by=/etc/apt/keyrings/syncthing-archive-keyring.gpg] https://apt.syncthing.net/ syncthing stable" > /etc/apt/sources.list.d/syncthing.list\'',
247+
{ interactive: true, requiresRoot: true }
248248
);
249-
await $.spawn('sudo apt-get update', { interactive: true });
250-
await $.spawn('sudo apt-get install -y syncthing', { interactive: true });
249+
await $.spawn('apt-get update', { interactive: true, requiresRoot: true });
250+
await $.spawn('apt-get install -y syncthing', { interactive: true, requiresRoot: true });
251251

252252
const shouldLaunchAtStartup = config.launchAtStartup ?? true;
253253
await this.setLaunchAtStartup(shouldLaunchAtStartup);
@@ -260,9 +260,9 @@ export class SyncthingResource extends Resource<SyncthingConfig> {
260260
const $ = getPty();
261261
await $.spawnSafe('systemctl --user stop syncthing');
262262
await $.spawnSafe('systemctl --user disable syncthing');
263-
await $.spawnSafe('sudo apt-get remove -y syncthing');
264-
await $.spawnSafe('sudo rm -f /etc/apt/sources.list.d/syncthing.list');
265-
await $.spawnSafe('sudo rm -f /etc/apt/keyrings/syncthing-archive-keyring.gpg');
263+
await $.spawnSafe('apt-get remove -y syncthing', { requiresRoot: true });
264+
await $.spawnSafe('rm -f /etc/apt/sources.list.d/syncthing.list', { requiresRoot: true });
265+
await $.spawnSafe('rm -f /etc/apt/keyrings/syncthing-archive-keyring.gpg', { requiresRoot: true });
266266
}
267267

268268
// ── Service management ────────────────────────────────────────────────────

test/syncthing/syncthing.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ describe('Syncthing resource integration tests', async () => {
210210
await testSpawn('brew services stop syncthing');
211211
await testSpawn('brew uninstall syncthing');
212212
} else {
213-
await testSpawn('systemctl --user stop syncthing');
214-
await testSpawn('systemctl --user disable syncthing');
215-
await testSpawn('sudo apt-get remove -y syncthing');
213+
// await testSpawn('systemctl --user stop syncthing');
214+
// await testSpawn('systemctl --user disable syncthing');
215+
// await testSpawn('apt-get remove -y syncthing', { requiresRoot: true });
216216
}
217217
}, 60_000);
218218
});

0 commit comments

Comments
 (0)