Initial import of verae-keep from zapier monorepo

This commit is contained in:
George Lambert 2026-09-11 19:55:20 -04:00
commit 100a35d589
17 changed files with 1000 additions and 0 deletions

33
test/intent.test.js Normal file
View file

@ -0,0 +1,33 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { emptyStore, record, pickIntent, writeUnitFile, readUnitFile, fromFleetService } from '../src/intent.js';
test('record and pick newest intent', () => {
const s = emptyStore();
record(s, 'a', 'run', 'keep');
const older = { state: 'stop', source: 'file', updatedAt: '2020-01-01T00:00:00Z' };
const picked = pickIntent(s.units.a, older);
assert.equal(picked.state, 'run');
assert.equal(picked.source, 'keep');
});
test('unit file round-trip', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'keep-intent-'));
const file = path.join(dir, 'intent.json');
writeUnitFile(file, 'x', 'pause', 'admin');
const got = readUnitFile(file);
assert.equal(got.state, 'pause');
assert.equal(got.source, 'admin');
});
test('fleet enabled false is stop; paused instance is pause', () => {
assert.equal(fromFleetService({ enabled: false, instances: [] }, 't-0').state, 'stop');
assert.equal(
fromFleetService({ enabled: true, instances: [{ id: 't-0', paused: true }] }, 't-0').state,
'pause',
);
assert.equal(fromFleetService({ enabled: true, instances: [{ id: 't-0', paused: false }] }, 't-0').state, 'run');
});