Record social browser governance actions

This commit is contained in:
ZacharyZhang-NY committed 2026-05-21 09:06:24 -04:00
1 parent f107ecba31
commit 935376f210
2 files changed
+43 -1

No files matched your search

@@ -29,6 +29,11 @@ export class SocialService {
createAccount(input: CreateSocialAccountInput): string {
const id = createId("soc");
const now = new Date().toISOString();
if (input.authorizedEmployeeId) {
const employee = this.db.prepare("select id from employees where id = ? and org_id = ?")
.get(input.authorizedEmployeeId, input.orgId);
if (!employee) throw new Error("Authorized employee was not found.");
}
this.db.prepare(`
insert into social_accounts(id, org_id, platform, handle, display_name, authorized_employee_id, created_at)
values (?, ?, ?, ?, ?, ?, ?)
@@ -89,6 +94,10 @@ export class SocialService {
});
this.attachNavigationPolicy(win, account.platform);
win.loadURL(PLATFORM_LOGIN_URL[account.platform]);
this.db.prepare(`
insert into browser_actions(id, org_id, social_account_id, action_type, policy_decision, evidence_file_id, created_at)
values (?, ?, ?, ?, ?, ?, ?)
`).run(createId("bact"), account.org_id, account.id, "login_window_opened", "allowed_human_login", null, new Date().toISOString());
this.audit.record({
orgId: account.org_id,
entityType: "social_account",
@@ -11,7 +11,8 @@ 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 { RISK_LEVEL, TASK_STATUS } from "../../src/shared/domain";
import { SocialService } from "../../src/main/services/social-service";
import { RISK_LEVEL, SOCIAL_PLATFORM, TASK_STATUS } from "../../src/shared/domain";
import { createId } from "../../src/shared/ids";
function createConnection(): DatabaseConnection {
@@ -211,6 +212,38 @@ 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("bootstraps the original onboarding chain with company, CEO, goal, project, task, and run", () => {
const connection = createConnection();
const onboarding = new OnboardingService({