P7 r3 fix: single-preview contract (syncAccess delegates drift-check+preview+push to pushIfNoDrift; acl_preview_failed mapped non-retryable) + test updates

This commit is contained in:
Hermes committed 2026-10-03 22:55:22 -07:00
1 parent d2d0d73477
commit 1e606bf0f3
2 files changed
+18 -22

No files matched your search

@@ -314,7 +314,7 @@ describe('tailscale provider: syncAccess() (DC-153 contract tests)', () => {
hostDeviceId: 'dev-host',
});
test('happy path: compiles → previews → pushes, returns {pushed, hash, usersAffected}', async () => {
test('happy path: compiles → drift-guarded push (preview happens EXACTLY once, inside push), returns {pushed, hash, usersAffected}', async () => {
const aclSync = makeAclSync();
const p = createTailscaleProvider({ coordClient: makeCoord(), aclSync });
const res = await p.syncAccess(input());
@@ -331,8 +331,9 @@ describe('tailscale provider: syncAccess() (DC-153 contract tests)', () => {
})
);
// Preview runs on the compiled policy, BEFORE the push.
expect(aclSync.preview).toHaveBeenCalledTimes(1);
expect(aclSync.preview).toHaveBeenCalledWith({ acls: [] });
// syncAccess no longer previews explicitly — engine.push's internal
// pushIfNoDrift does drift-check → preview → push (single preview).
expect(aclSync.preview).not.toHaveBeenCalled();
expect(aclSync.push).toHaveBeenCalledWith({ acls: [] });
});
@@ -352,10 +353,12 @@ describe('tailscale provider: syncAccess() (DC-153 contract tests)', () => {
expect(aclSync.push).not.toHaveBeenCalled();
});
test('preview errors[] → ProviderError acl_preview_failed, NOTHING pushed', async () => {
test('preview errors[] (thrown inside drift-guarded push) → ProviderError acl_preview_failed, NOTHING pushed', async () => {
// syncAccess no longer previews explicitly; pushIfNoDrift previews
// internally, so the internal preview failure surfaces THROUGH push.
const aclSync = makeAclSync({
preview: jest.fn(() => Promise.reject(new AclPushError('ACL preview reported errors', {
code: 'acl_rejected',
push: jest.fn(() => Promise.reject(new AclPushError('ACL preview reported errors', {
code: 'acl_preview_failed',
cause: ['bad dst'],
}))),
});
@@ -365,7 +368,7 @@ describe('tailscale provider: syncAccess() (DC-153 contract tests)', () => {
code: 'acl_preview_failed',
retryable: false,
});
expect(aclSync.push).not.toHaveBeenCalled();
expect(aclSync.push).toHaveBeenCalledTimes(1);
});
test('push API failure (acl_rejected) → ProviderError bad_input, mapped not leaked', async () => {