feat(new): enforce social publishing governance

Amp-Thread-ID: https://ampcode.com/threads/T-019e55df-9bcd-73e6-9935-c1e6238cd273
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
ZacharyZhang-NYandAmp committed 2026-05-23 14:18:34 -04:00
1 parent 8a1389bcbc
commit 6d99f515c7
10 files changed
+643 -141

No files matched your search

@@ -5,15 +5,13 @@ import { randomUUID } from "node:crypto";
import { DatabaseSync } from "node:sqlite";
import { describe, expect, test } from "vitest";
import { DatabaseConnection } from "../../src/main/database/connection";
import { FileService } from "../../src/main/services/file-service";
import { OrganizationService } from "../../src/main/services/organization-service";
import { SnapshotService } from "../../src/main/services/snapshot-service";
import { SkillService } from "../../src/main/services/skill-service";
import { ChatService } from "../../src/main/services/chat-service";
import { MigrationService } from "../../src/main/services/migration-service";
import { OnboardingService } from "../../src/main/services/onboarding-service";
import { SocialService } from "../../src/main/services/social-service";
import { RISK_LEVEL, SOCIAL_PLATFORM, TASK_STATUS } from "../../src/shared/domain";
import { RISK_LEVEL, TASK_STATUS } from "../../src/shared/domain";
import { createId } from "../../src/shared/ids";
function createConnection(): DatabaseConnection {
@@ -398,91 +396,6 @@ describe("domain services", () => {
connection.close();
});
test("creates social accounts with employee grants", () => {
const connection = createConnection();
const organization = new OrganizationService(connection.db);
const social = new SocialService(connection.db);
const snapshot = new SnapshotService(connection.db);
let orgId = "";
let employeeId = "";
connection.transaction(() => {
orgId = organization.createOrganization({
organizationName: "Acme Operations",
employeeName: "Dana Lee",
mission: "Coordinate agents with auditable approvals.",
goal: "Ship a verified control plane.",
});
employeeId = (connection.db.prepare("select id from employees where org_id = ?")
.get(orgId) as { id: string }).id;
social.createAccount({
orgId,
platform: SOCIAL_PLATFORM.X,
handle: "@acme",
displayName: "Acme",
authorizedEmployeeId: employeeId,
});
});
const state = snapshot.load();
expect(state.socialAccounts).toHaveLength(1);
expect(state.socialAccountGrants[0]?.employeeId).toBe(employeeId);
connection.close();
});
test("pins files and schedules social posts", () => {
const connection = createConnection();
const organization = new OrganizationService(connection.db);
const social = new SocialService(connection.db);
const files = new FileService(connection.db, join(tmpdir(), `artifacts-${randomUUID()}`));
const snapshot = new SnapshotService(connection.db);
let orgId = "";
let socialAccountId = "";
let fileId = "";
let employeeId = "";
connection.transaction(() => {
orgId = organization.createOrganization({
organizationName: "Acme Operations",
employeeName: "Dana Lee",
mission: "Coordinate agents with auditable approvals.",
goal: "Ship a verified control plane.",
});
employeeId = (connection.db.prepare("select id from employees where org_id = ?").get(orgId) as { id: string }).id;
socialAccountId = social.createAccount({
orgId,
platform: SOCIAL_PLATFORM.X,
handle: "@acme",
displayName: "Acme",
authorizedEmployeeId: employeeId,
});
fileId = createId("fil");
connection.db.prepare(`
insert into file_objects(
id, org_id, name, kind, size_bytes, sha256, storage_path,
owner_type, owner_id, space_id, pinned, created_at, updated_at
)
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`).run(fileId, orgId, "launch-thread.md", "md", 256, "abc", "artifacts/launch-thread.md", "employee", employeeId, null, 0, new Date().toISOString(), new Date().toISOString());
files.setPinned(orgId, fileId, true);
social.createScheduledPost({
orgId,
socialAccountId,
bodyMd: "Pilot starts Friday.",
scheduledFor: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
state: "scheduled",
createdByEmployeeId: employeeId,
});
});
const state = snapshot.load();
expect(state.files[0]?.pinned).toBe(true);
expect(state.scheduledPosts).toHaveLength(1);
expect(state.scheduledPosts[0]?.state).toBe("scheduled");
expect(state.scheduledPosts[0]?.socialAccountId).toBe(socialAccountId);
connection.close();
});
test("bootstraps the original onboarding chain with company, CEO, goal, project, task, and run", () => {
const connection = createConnection();
const onboarding = new OnboardingService({