Fill the SCUM user and vehicle tables from the plugin-declared database read path
The SCUM 用户管理 list stayed empty because the typed scum_user and scum_vehicle tables had no producer: the run ingest endpoint is signed-run only, and the previously registered plugin templates asked for a Run database capability the endpoint never advertises. The plugin now declares bounded, read-only SQLite projections for players and vehicles (sql/scum-db-v57/*.sql with query schemas), and the platform dispatches those templates as durable remote.run.db.sqlite.query jobs on run heartbeat and page open, then projects the returned rows into the typed SCUM tables through the same shared ingest path used by signed run facts.
This commit is contained in:
@@ -140,18 +140,58 @@ describe("plugin manifest validation", () => {
|
||||
|
||||
it("removes raw SQL command surfaces", () => {
|
||||
const pluginDir = path.join(pluginsRoot, "examples/scum-server-plugin");
|
||||
const manifest = JSON.parse(fs.readFileSync(path.join(pluginDir, "manifest.json"), "utf8")) as { gameClientBridge: { commands: Array<{ type: string; payloadSchemaRef: string }>; queryTemplates?: Array<{ key: string }> } };
|
||||
const manifest = JSON.parse(fs.readFileSync(path.join(pluginDir, "manifest.json"), "utf8")) as {
|
||||
gameClientBridge: {
|
||||
commands: Array<{ type: string; payloadSchemaRef: string }>;
|
||||
queryTemplates?: Array<{ key: string; sqlRef: string }>;
|
||||
pages: Array<{ pageKey: string; queryTemplateKeys?: string[] }>;
|
||||
};
|
||||
};
|
||||
expect(manifest.gameClientBridge.commands.some((command) => command.type === "diagnostic.ping")).toBe(false);
|
||||
expect(manifest.gameClientBridge.commands.map((command) => command.type)).not.toEqual(expect.arrayContaining(["config.read", "config.patch", "database.request", "management.rcon.request", "management.program.request"]));
|
||||
expect(manifest.gameClientBridge.queryTemplates ?? []).toEqual([]);
|
||||
for (const template of manifest.gameClientBridge.queryTemplates ?? []) {
|
||||
expect(template.sqlRef).toMatch(/^sql\/scum-db-v57\/[a-z-]+\.sql$/);
|
||||
}
|
||||
expect(manifest.gameClientBridge.pages.some((page) => (page.queryTemplateKeys ?? []).length > 0)).toBe(false);
|
||||
expect(fs.existsSync(path.join(pluginDir, "schemas/bridge/queries/SCUM_DB_CONTRACT.md"))).toBe(false);
|
||||
});
|
||||
|
||||
it("does not declare SCUM direct database templates or bridge projections", () => {
|
||||
it("declares bounded SCUM database read templates for platform-dispatched projections", () => {
|
||||
const manifest = JSON.parse(fs.readFileSync(path.join(pluginsRoot, "examples/scum-server-plugin/manifest.json"), "utf8")) as {
|
||||
gameClientBridge: { lifecycleProjections?: unknown[]; queryTemplates?: Array<{ key: string; engine: string; transportKey: string; targetKey: string; projections?: unknown[] }> };
|
||||
gameClientBridge: {
|
||||
lifecycleProjections?: unknown[];
|
||||
queryTemplates?: Array<{
|
||||
key: string;
|
||||
engine: string;
|
||||
transportKey: string;
|
||||
targetKey: string;
|
||||
pollIntervalSeconds: number;
|
||||
maxRows: number;
|
||||
timeoutSeconds: number;
|
||||
projections?: Array<{ collection: string; rowPath: string; upsertKeys: string[] }>;
|
||||
}>;
|
||||
};
|
||||
};
|
||||
expect(manifest.gameClientBridge.queryTemplates ?? []).toEqual([]);
|
||||
const templates = manifest.gameClientBridge.queryTemplates ?? [];
|
||||
expect(templates.map((template) => template.key)).toEqual(["scum.database.players", "scum.database.vehicles"]);
|
||||
for (const template of templates) {
|
||||
expect(template.engine).toBe("sqlite");
|
||||
expect(template.transportKey).toBe("scum-database");
|
||||
expect(template.targetKey).toBe("scum-database");
|
||||
expect(template.pollIntervalSeconds).toBeGreaterThan(0);
|
||||
expect(template.pollIntervalSeconds).toBeLessThanOrEqual(300);
|
||||
expect(template.maxRows).toBeGreaterThan(0);
|
||||
expect(template.maxRows).toBeLessThanOrEqual(500);
|
||||
expect(template.timeoutSeconds).toBeGreaterThan(0);
|
||||
expect(template.timeoutSeconds).toBeLessThanOrEqual(60);
|
||||
expect((template.projections ?? []).length).toBe(1);
|
||||
for (const projection of template.projections ?? []) {
|
||||
expect(projection.rowPath).toBe("rows");
|
||||
expect(projection.upsertKeys.length).toBeGreaterThan(0);
|
||||
}
|
||||
}
|
||||
expect(templates.find((template) => template.key === "scum.database.players")?.projections?.[0].collection).toBe("scum.users");
|
||||
expect(templates.find((template) => template.key === "scum.database.vehicles")?.projections?.[0].collection).toBe("scum.vehicles");
|
||||
expect(manifest.gameClientBridge.lifecycleProjections).toBeUndefined();
|
||||
});
|
||||
|
||||
@@ -257,7 +297,7 @@ describe("plugin manifest validation", () => {
|
||||
expect(unsafe.some((error) => error.includes("raw host path"))).toBe(true);
|
||||
});
|
||||
|
||||
it("declares management transports without SCUM database access", () => {
|
||||
it("declares a read-only SCUM database transport beside the management transports", () => {
|
||||
const manifestPath = path.join(pluginsRoot, "examples/scum-server-plugin/manifest.json");
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8")) as {
|
||||
remoteAccess?: { databaseEngines?: string[]; runCapabilities?: string[] };
|
||||
@@ -271,14 +311,18 @@ describe("plugin manifest validation", () => {
|
||||
expect(local?.capabilities).toContain("remote.run.rcon.command");
|
||||
expect(local?.transportKeys).toContain("scum-management");
|
||||
expect(local?.transportKeys).not.toContain("scum-database");
|
||||
expect(manifest.remoteAccess?.databaseEngines).toEqual([]);
|
||||
expect(manifest.remoteAccess?.runCapabilities).not.toEqual(expect.arrayContaining(["remote.run.db.sqlite.query", "remote.run.db.sqlite.execute"]));
|
||||
expect(manifest.runtimeProfiles?.dataTargets).toEqual([]);
|
||||
expect(manifest.remoteAccess?.databaseEngines).toEqual(["sqlite"]);
|
||||
expect(manifest.remoteAccess?.runCapabilities).toContain("remote.run.db.sqlite.query");
|
||||
expect(manifest.remoteAccess?.runCapabilities).not.toContain("remote.run.db.sqlite.execute");
|
||||
expect(manifest.runtimeProfiles?.dataTargets).toEqual([
|
||||
expect.objectContaining({ key: "scum-database", kind: "sqlite.snapshot" })
|
||||
]);
|
||||
expect(manifest.runtimeProfiles?.transportProfiles).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({ key: "scum-management", kind: "rcon", capabilities: ["remote.run.rcon.command"] }),
|
||||
expect.objectContaining({ key: "scum-program", kind: "program", capabilities: ["remote.run.program.command"] })
|
||||
expect.objectContaining({ key: "scum-program", kind: "program", capabilities: ["remote.run.program.command"] }),
|
||||
expect.objectContaining({ key: "scum-database", kind: "sqlite", targetKey: "scum-database", capabilities: ["remote.run.db.sqlite.query"] })
|
||||
]));
|
||||
expect(manifest.runtimeProfiles?.transportProfiles?.some((profile) => profile.key === "scum-database" || profile.kind === "sqlite")).toBe(false);
|
||||
expect(manifest.runtimeProfiles?.transportProfiles?.flatMap((profile) => profile.capabilities ?? [])).not.toContain("remote.run.db.sqlite.execute");
|
||||
});
|
||||
|
||||
it("covers the SCUM 4.1 bridge and lifecycle declarations", () => {
|
||||
@@ -313,7 +357,7 @@ describe("plugin manifest validation", () => {
|
||||
const serialized = JSON.stringify(manifest).toLowerCase();
|
||||
|
||||
expect(serialized).not.toContain("local-proof");
|
||||
expect(manifest.version).toBe("0.1.19");
|
||||
expect(manifest.version).toBe("0.1.22");
|
||||
expect(installAction.environment?.SERVER_TEMPLATE).toBe("scum-server");
|
||||
expect(manifest.permissions).toEqual(expect.arrayContaining(["server.game-client.read", "server.game-client.command", "server.game-client.maintenance"]));
|
||||
expect(manifest.gameClientBridge.commands.map((command) => command.type)).toEqual(expect.arrayContaining([
|
||||
@@ -328,7 +372,7 @@ describe("plugin manifest validation", () => {
|
||||
expect(manifest.gameClientBridge.snapshots.map((snapshot) => snapshot.type)).toEqual(expect.arrayContaining(["online.sessions", "players", "squads", "vehicles", "flags"]));
|
||||
expect(manifest.runtimeProfiles?.clientManagers).toBeUndefined();
|
||||
expect(manifest.gameClientBridge.lifecycleProjections).toBeUndefined();
|
||||
expect(manifest.gameClientBridge.queryTemplates ?? []).toEqual([]);
|
||||
expect((manifest.gameClientBridge.queryTemplates ?? []).map((template) => template.key)).toEqual(["scum.database.players", "scum.database.vehicles"]);
|
||||
expect(manifest.gameClientBridge.pages.map((page) => page.pageKey)).toEqual(expect.arrayContaining(["players", "squads", "live-map", "gifts", "workflows"]));
|
||||
expect(manifest.gameClientBridge.pages.map((page) => page.pageKey)).not.toContain("files-config");
|
||||
expect(manifest.gameClientBridge.pages.some((page) => page.queryTemplateKeys?.length)).toBe(false);
|
||||
@@ -452,7 +496,7 @@ describe("plugin manifest validation", () => {
|
||||
expect(manifest.gameClientBridge.pages.find((page) => page.pageKey === "live-map")?.snapshotTypes).toEqual(expect.arrayContaining(["players", "vehicles", "flags"]));
|
||||
});
|
||||
|
||||
it("keeps SCUM user and vehicle data off direct database query templates", () => {
|
||||
it("keeps SCUM database reads platform-dispatched, read-only, and package-scoped", () => {
|
||||
const pluginDir = path.join(pluginsRoot, "examples/scum-server-plugin");
|
||||
const manifest = JSON.parse(fs.readFileSync(path.join(pluginDir, "manifest.json"), "utf8")) as {
|
||||
capabilities: string[];
|
||||
@@ -468,15 +512,32 @@ describe("plugin manifest validation", () => {
|
||||
};
|
||||
assetFiles?: Array<{ path: string }>;
|
||||
};
|
||||
expect(manifest.gameClientBridge.queryTemplates ?? []).toEqual([]);
|
||||
expect(manifest.capabilities).not.toEqual(expect.arrayContaining(["remote.run.db.sqlite.query", "remote.run.db.sqlite.execute"]));
|
||||
expect(manifest.remoteAccess?.runCapabilities).not.toEqual(expect.arrayContaining(["remote.run.db.sqlite.query", "remote.run.db.sqlite.execute"]));
|
||||
expect(manifest.remoteAccess?.databaseEngines).toEqual([]);
|
||||
const templates = manifest.gameClientBridge.queryTemplates ?? [];
|
||||
expect(templates.length).toBe(2);
|
||||
const assetPaths = (manifest.assetFiles ?? []).map((file) => file.path);
|
||||
for (const template of templates) {
|
||||
const sqlRef = String(template.sqlRef);
|
||||
expect(sqlRef.startsWith("sql/scum-db-v57/")).toBe(true);
|
||||
expect(assetPaths).toContain(sqlRef);
|
||||
expect(fs.existsSync(path.join(pluginDir, sqlRef))).toBe(true);
|
||||
}
|
||||
expect(manifest.capabilities).toContain("remote.run.db.sqlite.query");
|
||||
expect(manifest.capabilities).not.toContain("remote.run.db.sqlite.execute");
|
||||
expect(manifest.remoteAccess?.runCapabilities).toContain("remote.run.db.sqlite.query");
|
||||
expect(manifest.remoteAccess?.runCapabilities).not.toContain("remote.run.db.sqlite.execute");
|
||||
expect(manifest.remoteAccess?.databaseEngines).toEqual(["sqlite"]);
|
||||
expect(manifest.remoteAccess?.rcon).toBe(true);
|
||||
expect(manifest.runtimeProfiles?.dataTargets).toEqual([]);
|
||||
expect(manifest.runtimeProfiles?.transportProfiles?.some((profile) => profile.kind === "sqlite" || profile.key === "scum-database")).toBe(false);
|
||||
expect((manifest.assetFiles ?? []).map((file) => file.path).some((assetPath) => assetPath.startsWith("sql/") || assetPath.includes("SCUM_DB_CONTRACT"))).toBe(false);
|
||||
expect(fs.existsSync(path.join(pluginDir, "sql/scum-db-v57"))).toBe(false);
|
||||
expect(manifest.runtimeProfiles?.dataTargets).toEqual([
|
||||
expect.objectContaining({ key: "scum-database", kind: "sqlite.snapshot" })
|
||||
]);
|
||||
expect(manifest.runtimeProfiles?.transportProfiles?.some((profile) => profile.kind === "sqlite" && profile.capabilities.includes("remote.run.db.sqlite.query"))).toBe(true);
|
||||
expect(manifest.gameClientBridge.pages.some((page) => (page.queryTemplateKeys ?? []).length > 0)).toBe(false);
|
||||
for (const template of templates) {
|
||||
const schemaRefs = [String(template.parameterSchemaRef), String(template.resultSchemaRef)];
|
||||
for (const schemaRef of schemaRefs) {
|
||||
expect(fs.existsSync(path.join(pluginDir, schemaRef))).toBe(true);
|
||||
}
|
||||
}
|
||||
const playersPage = manifest.gameClientBridge.pages.find((page) => page.pageKey === "players");
|
||||
const squadsPage = manifest.gameClientBridge.pages.find((page) => page.pageKey === "squads");
|
||||
const mapPage = manifest.gameClientBridge.pages.find((page) => page.pageKey === "live-map");
|
||||
|
||||
Reference in New Issue
Block a user