feat: add Semaphore Sync job
All checks were successful
CI / test (pull_request) Successful in 15s
CI / build-dev (pull_request) Has been skipped

Fetches Semaphore project inventory via Bearer auth, parses the
Ansible INI format to extract hostnames, and sets semaphore=1/0
on matching instances.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-28 19:34:45 -04:00
parent 0b350f3b28
commit a934db1a14
4 changed files with 65 additions and 6 deletions

View File

@@ -585,4 +585,21 @@ describe('POST /api/jobs/:id/run', () => {
const res = await request(app).post(`/api/jobs/${id}/run`)
expect(res.status).toBe(500)
})
it('semaphore_sync: parses ansible inventory and updates instances', async () => {
const semaphoreJob = {
key: 'semaphore_sync', name: 'Semaphore Sync', description: 'test',
enabled: 0, schedule: 60,
config: JSON.stringify({ api_url: 'http://semaphore:3000/api/project/1/inventory/1', api_token: 'bearer-token' }),
}
createJob(semaphoreJob)
const id = (await request(app).get('/api/jobs')).body[0].id
vi.stubGlobal('fetch', vi.fn().mockResolvedValueOnce({
ok: true,
json: async () => ({ inventory: '[production]\nplex\nhomeassistant\n' }),
}))
const res = await request(app).post(`/api/jobs/${id}/run`)
expect(res.status).toBe(200)
expect(res.body.summary).toMatch(/updated of/)
})
})