Skip to content

Commit 859a73a

Browse files
committed
fix: fixed syncthing bugs and fixed test runner bug
1 parent f18059f commit 859a73a

4 files changed

Lines changed: 19 additions & 42 deletions

File tree

scripts/run-tests.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ async function launchPersistentVm(operatingSystem: string) {
123123

124124
const { data: ipAddr } = await testSpawn(`tart ip ${newVmName}`);
125125
await testSpawn(`sshpass -p "admin" rsync -avz -e 'ssh -o PubkeyAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' --exclude 'node_modules' --exclude '.git' --exclude 'dist' --exclude '.fleet' ${process.cwd()} admin@${ipAddr}:~`);
126+
if (operatingSystem === 'darwin') {
127+
await testSpawn(`tart exec ${newVmName} ${shell} -i -c "mv ~/.zprofile ~/.zshenv"`);
128+
}
129+
126130
await testSpawn(`tart exec ${newVmName} ${shell} -i -c "cd ~/codify-homebrew-plugin && npm ci"`);
127131
console.log('Finished installing dependencies. Start tests in a new terminal window.');
128132

src/resources/syncthing/syncthing-device.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const schema = z
1818
deviceId: z
1919
.string()
2020
.describe('The Syncthing device ID (e.g. XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX)'),
21-
name: z
21+
deviceName: z
2222
.string()
2323
.optional()
2424
.describe('Human-readable label for this device'),
@@ -79,7 +79,7 @@ export class SyncthingDeviceResource extends Resource<SyncthingDeviceConfig> {
7979
identifyingParameters: ['deviceId'],
8080
},
8181
parameterSettings: {
82-
name: { type: 'string', canModify: true },
82+
deviceName: { type: 'string', canModify: true },
8383
addresses: { type: 'array', canModify: true },
8484
autoAcceptFolders: { type: 'boolean', canModify: true },
8585
paused: { type: 'boolean', canModify: true },
@@ -107,10 +107,10 @@ export class SyncthingDeviceResource extends Resource<SyncthingDeviceConfig> {
107107

108108
async create(plan: CreatePlan<SyncthingDeviceConfig>): Promise<void> {
109109
const $ = getPty();
110-
const { deviceId, name, addresses, autoAcceptFolders, paused, compression, maxSendKbps, maxRecvKbps } =
110+
const { deviceId, deviceName, addresses, autoAcceptFolders, paused, compression, maxSendKbps, maxRecvKbps } =
111111
plan.desiredConfig;
112112

113-
const args = buildDeviceAddArgs({ deviceId, name, addresses, autoAcceptFolders, paused, compression, maxSendKbps, maxRecvKbps });
113+
const args = buildDeviceAddArgs({ deviceId, deviceName, addresses, autoAcceptFolders, paused, compression, maxSendKbps, maxRecvKbps });
114114
await $.spawn(`syncthing cli config devices add ${args}`, { interactive: true });
115115
}
116116

@@ -150,19 +150,14 @@ export class SyncthingDeviceResource extends Resource<SyncthingDeviceConfig> {
150150
return null;
151151
}
152152

153-
let ids: string[];
154-
try {
155-
ids = JSON.parse(listData) as string[];
156-
} catch {
157-
return null;
158-
}
153+
const ids = listData.split('\n').map((s) => s.trim()).filter(Boolean);
159154

160155
if (!ids.includes(deviceId)) {
161156
return null;
162157
}
163158

164159
// Fetch the full device configuration
165-
const { status, data } = await $.spawnSafe(`syncthing cli config devices ${deviceId}`);
160+
const { status, data } = await $.spawnSafe(`syncthing cli config devices ${deviceId} dump-json`);
166161
if (status !== SpawnStatus.SUCCESS) {
167162
return null;
168163
}
@@ -180,7 +175,7 @@ export class SyncthingDeviceResource extends Resource<SyncthingDeviceConfig> {
180175
function deviceFromRaw(raw: RawDevice): Partial<SyncthingDeviceConfig> {
181176
return {
182177
deviceId: raw.deviceID,
183-
name: raw.name || undefined,
178+
deviceName: raw.name || undefined,
184179
addresses: raw.addresses,
185180
compression: raw.compression as SyncthingDeviceConfig['compression'],
186181
autoAcceptFolders: raw.autoAcceptFolders,
@@ -192,7 +187,7 @@ function deviceFromRaw(raw: RawDevice): Partial<SyncthingDeviceConfig> {
192187

193188
function deviceOptionCliPath(key: keyof SyncthingDeviceConfig): string | undefined {
194189
const map: Partial<Record<keyof SyncthingDeviceConfig, string>> = {
195-
name: 'name',
190+
deviceName: 'name',
196191
autoAcceptFolders: 'autoAcceptFolders',
197192
paused: 'paused',
198193
compression: 'compression',
@@ -206,7 +201,7 @@ function buildDeviceAddArgs(config: Partial<SyncthingDeviceConfig>): string {
206201
const parts: string[] = [];
207202

208203
if (config.deviceId) parts.push(`--device-id ${config.deviceId}`);
209-
if (config.name) parts.push(`--name "${config.name}"`);
204+
if (config.deviceName) parts.push(`--name "${config.deviceName}"`);
210205
if (config.addresses?.length) parts.push(`--addresses ${config.addresses.join(',')}`);
211206
if (config.autoAcceptFolders !== undefined)
212207
parts.push(`--auto-accept-folders=${config.autoAcceptFolders}`);

src/resources/syncthing/syncthing-folder.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import {
55
ParameterChange,
66
Resource,
77
ResourceSettings,
8-
SpawnStatus,
98
getPty,
109
z,
10+
SpawnStatus,
1111
} from '@codifycli/plugin-core';
1212
import { OS } from '@codifycli/schemas';
1313

@@ -162,27 +162,7 @@ export class SyncthingFolderResource extends Resource<SyncthingFolderConfig> {
162162
private async fetchFolder(folderId: string): Promise<RawFolder | null> {
163163
const $ = getPty();
164164

165-
// Verify the folder ID exists in the configured list
166-
const { status: listStatus, data: listData } = await $.spawnSafe(
167-
'syncthing cli config folders list'
168-
);
169-
if (listStatus !== SpawnStatus.SUCCESS) {
170-
return null;
171-
}
172-
173-
let ids: string[];
174-
try {
175-
ids = JSON.parse(listData) as string[];
176-
} catch {
177-
return null;
178-
}
179-
180-
if (!ids.includes(folderId)) {
181-
return null;
182-
}
183-
184-
// Fetch the full folder configuration
185-
const { status, data } = await $.spawnSafe(`syncthing cli config folders ${folderId}`);
165+
const { status, data } = await $.spawnSafe(`syncthing cli config folders ${folderId} dump-json`);
186166
if (status !== SpawnStatus.SUCCESS) {
187167
return null;
188168
}

test/syncthing/syncthing.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ describe('Syncthing resource integration tests', async () => {
155155
const listResult = await testSpawn('syncthing cli config folders list');
156156
expect(listResult.status).toBe(SpawnStatus.SUCCESS);
157157

158-
const ids: string[] = JSON.parse(listResult.data);
159-
expect(ids).toContain('codify-test');
158+
expect(listResult.data).toContain('codify-test');
160159
},
161160
validateDestroy: async () => {
162161
expect(await testSpawn('which syncthing')).toMatchObject({
@@ -173,7 +172,7 @@ describe('Syncthing resource integration tests', async () => {
173172

174173
it('Can add and remove a remote device', { timeout: 300_000 }, async () => {
175174
// Use a deterministic but fictitious device ID that Syncthing will accept
176-
const testDeviceId = 'AAAAAAA-BBBBBBB-CCCCCCC-DDDDDDD-EEEEEEE-FFFFFFF-GGGGGGG-HHHHHHH';
175+
const testDeviceId = 'MFZWI3D-BONSGYC-YLTMRWG-C43ENR5-QXGZDMM-FZWI3DP-BONSGYY-LTMRWAD';
177176

178177
await PluginTester.fullTest(
179178
pluginPath,
@@ -182,7 +181,7 @@ describe('Syncthing resource integration tests', async () => {
182181
{
183182
type: 'syncthing-device',
184183
deviceId: testDeviceId,
185-
name: 'Codify Test Device',
184+
deviceName: 'Codify Test Device',
186185
addresses: ['dynamic'],
187186
autoAcceptFolders: false,
188187
compression: 'metadata',
@@ -193,8 +192,7 @@ describe('Syncthing resource integration tests', async () => {
193192
const listResult = await testSpawn('syncthing cli config devices list');
194193
expect(listResult.status).toBe(SpawnStatus.SUCCESS);
195194

196-
const ids: string[] = JSON.parse(listResult.data);
197-
expect(ids).toContain(testDeviceId);
195+
expect(listResult.data).toContain(testDeviceId);
198196
},
199197
validateDestroy: async () => {
200198
expect(await testSpawn('which syncthing')).toMatchObject({

0 commit comments

Comments
 (0)