Add browser platform governance records

This commit is contained in:
ZacharyZhang-NY committed 2026-05-23 21:17:03 -04:00
1 parent 18e0c6338e
commit eab282d8b1
12 files changed
+536 -78

No files matched your search

@@ -23,7 +23,7 @@ describe("domain services", () => {
const connection = createConnection();
const rows = connection.db.prepare("select version from schema_migrations order by version asc").all() as Array<{ version: number }>;
expect(rows.map((row) => row.version)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]);
expect(rows.map((row) => row.version)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]);
connection.close();
});
@@ -146,6 +146,9 @@ describe("migration service", () => {
create table file_access_grants(id text primary key, org_id text, file_id text, source_message_id text, source_thread_id text);
create table social_accounts(id text primary key, org_id text, authorized_employee_id text);
create table social_account_grants(id text primary key, org_id text, social_account_id text, employee_id text);
create table browser_session_containers(id text primary key, org_id text, social_account_id text);
create table browser_action_policies(id text primary key, org_id text, social_account_id text);
create table social_approval_routes(id text primary key, org_id text, social_account_id text, route_to_id text);
create table browser_actions(id text primary key, org_id text, social_account_id text, evidence_file_id text);
create table scheduled_posts(id text primary key, org_id text, social_account_id text, approval_id text, created_by_employee_id text);
create table policy_rules(id text primary key, org_id text);
@@ -211,6 +214,9 @@ describe("migration service", () => {
insert into skill_catalog_tags(skill_id, tag, tag_type) values ('skill-1', 'engineering', 'department');
insert into social_accounts(id, org_id, authorized_employee_id) values ('social-1', 'org-1', 'emp-1');
insert into social_account_grants(id, org_id, social_account_id, employee_id) values ('grant-1', 'org-1', 'social-1', 'emp-1');
insert into browser_session_containers(id, org_id, social_account_id) values ('container-1', 'org-1', 'social-1');
insert into browser_action_policies(id, org_id, social_account_id) values ('browser-policy-1', 'org-1', 'social-1');
insert into social_approval_routes(id, org_id, social_account_id, route_to_id) values ('social-route-1', 'org-1', 'social-1', 'emp-1');
insert into browser_actions(id, org_id, social_account_id, evidence_file_id) values ('browser-1', 'org-1', 'social-1', 'file-1');
insert into scheduled_posts(id, org_id, social_account_id, approval_id, created_by_employee_id) values ('post-1', 'org-1', 'social-1', 'approval-1', 'emp-1');
insert into policy_rules(id, org_id) values ('policy-1', 'org-1');
@@ -247,6 +253,9 @@ describe("migration service", () => {
expect(body.tableCounts.provider_requests).toBe(1);
expect(body.tableCounts.provider_usage_windows).toBe(1);
expect(body.tableCounts.provider_rate_limit_observations).toBe(1);
expect(body.tableCounts.browser_session_containers).toBe(1);
expect(body.tableCounts.browser_action_policies).toBe(1);
expect(body.tableCounts.social_approval_routes).toBe(1);
expect(body.tableCounts.compliance_exports).toBe(1);
expect(body.tableCounts.audit_replay_runs).toBe(1);
expect(body.tableCounts.rollback_snapshots).toBe(1);
@@ -266,6 +275,9 @@ describe("migration service", () => {
expect(body.idMaps.rollback_snapshots).toEqual(["rollback-1"]);
expect(body.idMaps.provider_usage_windows).toEqual(["usage-1"]);
expect(body.idMaps.provider_rate_limit_observations).toEqual(["quota-1"]);
expect(body.idMaps.browser_session_containers).toEqual(["container-1"]);
expect(body.idMaps.browser_action_policies).toEqual(["browser-policy-1"]);
expect(body.idMaps.social_approval_routes).toEqual(["social-route-1"]);
connection.close();
});
@@ -8,7 +8,7 @@ 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 { SocialService } from "../../src/main/services/social-service";
import { APPROVAL_STATE, SOCIAL_PLATFORM } from "../../src/shared/domain";
import { APPROVAL_STATE, ROUTE_TO_TYPE, SOCIAL_PLATFORM } from "../../src/shared/domain";
import { createId } from "../../src/shared/ids";
function createConnection(): DatabaseConnection {
@@ -62,6 +62,25 @@ describe("social service", () => {
const grantScope = JSON.parse(state.socialAccountGrants[0]!.scopeJson) as { actions: string[]; riskCeiling: string };
expect(state.socialAccounts).toHaveLength(1);
expect(state.socialAccountGrants[0]?.employeeId).toBe(employeeId);
expect(state.browserSessionContainers[0]).toMatchObject({
socialAccountId: state.socialAccounts[0]?.id,
platform: SOCIAL_PLATFORM.X,
permissionPolicy: "deny_all",
sandboxEnabled: true,
});
expect(JSON.parse(state.browserSessionContainers[0]!.hostAllowlistJson)).toEqual(["x.com", "twitter.com"]);
expect(state.browserActionPolicies.map((policy) => policy.actionType).sort()).toEqual(["approve", "draft", "login"]);
expect(state.browserActionPolicies.find((policy) => policy.actionType === "approve")).toMatchObject({
approvalRequired: true,
approvalKind: "social_publish",
riskLevel: "medium",
});
expect(state.socialApprovalRoutes[0]).toMatchObject({
socialAccountId: state.socialAccounts[0]?.id,
actionType: "approve",
approvalKind: "social_publish",
routeToId: employeeId,
});
expect(state.auditEvents.find((event) => event.entityType === "social_account")?.actorId).toBe(employeeId);
expect(grantScope.actions).toEqual(["login", "draft", "approve"]);
expect(grantScope.riskCeiling).toBe("medium");
@@ -137,6 +156,49 @@ describe("social service", () => {
connection.close();
});
test("assigns social publish approvals to the account authorizer", () => {
const connection = createConnection();
const organization = new OrganizationService(connection.db);
const social = new SocialService(connection.db);
const snapshot = new SnapshotService(connection.db);
let orgId = "";
let authorizerId = "";
let approvalId = "";
connection.transaction(() => {
orgId = createOrganization(organization);
const creatorId = firstEmployeeId(connection, orgId);
authorizerId = createEmployee(connection, orgId, "Riley Chen");
const socialAccountId = social.createAccount({
orgId,
platform: SOCIAL_PLATFORM.INSTAGRAM,
handle: "acme",
displayName: "Acme",
createdByEmployeeId: creatorId,
authorizedEmployeeId: authorizerId,
});
const postId = social.createScheduledPost({
orgId,
socialAccountId,
bodyMd: "Launch update.",
scheduledFor: new Date(Date.now() + 2 * 60 * 60 * 1000).toISOString(),
createdByEmployeeId: authorizerId,
});
social.setScheduledPostState({ orgId, scheduledPostId: postId, state: "scheduled", employeeId: authorizerId });
approvalId = (connection.db.prepare("select approval_id from scheduled_posts where id = ?")
.get(postId) as { approval_id: string }).approval_id;
});
const state = snapshot.load();
expect(state.approvalAssignments).toContainEqual(expect.objectContaining({
approvalId,
assigneeType: ROUTE_TO_TYPE.EMPLOYEE,
assigneeId: authorizerId,
routingRuleId: null,
}));
connection.close();
});
test("rejects social actions without account grants", () => {
const connection = createConnection();
const organization = new OrganizationService(connection.db);