This repository has been archived on 2026-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as
opaque submodule gitlinks on GitHub) into fully-tracked first-party content.

AITM now merges its 7 vendored repos as first-party engines:
- memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts
- git: vendored C git (bundled binary) + gitnexus (in-process code intelligence)
- agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess)

Includes the full session's product build: Gitgram web/mobile/backend features,
AITM website/CLI/MCP, the unified memory layer, engine build tooling
(scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md),
and extensive test suites.

Build artifacts, node_modules, external/, and gemini-cli are gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 14:14:09 +03:00

90 lines
2.6 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
import { triggerWebhooksForUser } from "../../src/services/webhookDelivery.js";
import {
mockCheckpoints,
mockRestoreEvents,
seedTestData,
} from "../setup.js";
import { recordRestoreEventAndEmitWebhooks } from "../../src/services/restoreEvents.js";
describe("restoreEvents service", () => {
beforeEach(() => {
seedTestData();
mockRestoreEvents.length = 0;
mockCheckpoints.length = 0;
vi.clearAllMocks();
});
it("records restore event and emits enriched webhooks", async () => {
mockCheckpoints.push({
id: "cp_to_001",
projectId: "proj_test_001",
userId: "user_test_001",
name: "After Fix",
description: "stable point",
scope: "files+chat",
manifestHash: "mh_to",
triggerType: "manual",
linkedCheckpointId: null,
createdAt: new Date("2026-01-01T10:00:00.000Z"),
});
mockCheckpoints.push({
id: "cp_from_001",
projectId: "proj_test_001",
userId: "user_test_001",
name: "Before Bug",
description: "bad point",
scope: "files+chat",
manifestHash: "mh_from",
triggerType: "after_action",
linkedCheckpointId: null,
createdAt: new Date("2026-01-01T09:00:00.000Z"),
});
const result = await recordRestoreEventAndEmitWebhooks({
userId: "user_test_001",
projectId: "proj_test_001",
fromCheckpointId: "cp_from_001",
toCheckpointId: "cp_to_001",
scopeType: "file",
scopePath: "src/index.ts",
source: "undo",
details: { reason: "rollback" },
});
expect(result.id).toBeTruthy();
expect(mockRestoreEvents.length).toBe(1);
expect(mockRestoreEvents[0].toCheckpointId).toBe("cp_to_001");
expect(mockRestoreEvents[0].fromCheckpointId).toBe("cp_from_001");
expect(mockRestoreEvents[0].scopeType).toBe("file");
const webhookMock = triggerWebhooksForUser as unknown as ReturnType<typeof vi.fn>;
expect(webhookMock).toHaveBeenCalledTimes(2);
expect(webhookMock).toHaveBeenCalledWith(
"user_test_001",
"checkpoint.restored",
expect.objectContaining({
restoreEventId: result.id,
checkpointId: "cp_to_001",
checkpointName: "After Fix",
fromCheckpointId: "cp_from_001",
fromCheckpointName: "Before Bug",
scopeType: "file",
})
);
expect(webhookMock).toHaveBeenCalledWith(
"user_test_001",
"restore.event",
expect.objectContaining({
restoreEventId: result.id,
toCheckpointId: "cp_to_001",
scopeType: "file",
source: "undo",
})
);
});
});