Add SCUM player query assets
This commit is contained in:
@@ -218,6 +218,32 @@ describe("plugin manifest validation", () => {
|
||||
expect(JSON.stringify(manifest.scumLiveData).toLowerCase()).not.toMatch(/select\s+.+from|sqlite:\/\/|mysql:\/\/|password|credential|socket|hostpath/);
|
||||
});
|
||||
|
||||
it("packages SCUM player read query assets with exact bounded result schemas", () => {
|
||||
const pluginDir = path.join(pluginsRoot, "examples/scum-server-plugin");
|
||||
const manifest = JSON.parse(fs.readFileSync(path.join(pluginDir, "manifest.json"), "utf8")) as GamePluginManifest & { scumLiveData: SCUMLiveDataManifestDeclaration };
|
||||
const assetPaths = new Set(manifest.assetFiles?.map((file) => file.path) ?? []);
|
||||
const queries = manifest.scumLiveData.sqliteQueries ?? [];
|
||||
expect(queries.map((query) => query.key)).toEqual(["scum-players-read", "scum-player-details-read", "scum-player-economy-read", "scum-player-session-enrichment-read"]);
|
||||
|
||||
for (const query of queries) {
|
||||
expect(assetPaths.has(query.assetPath)).toBe(true);
|
||||
const assetPath = path.join(pluginDir, query.assetPath);
|
||||
const actualDigest = `sha256:${crypto.createHash("sha256").update(fs.readFileSync(assetPath)).digest("hex")}`;
|
||||
expect(query.digest).toBe(actualDigest);
|
||||
const asset = JSON.parse(fs.readFileSync(assetPath, "utf8")) as { requiredSchemaFingerprint?: string; statement?: string; safety?: { queryOnly?: boolean; readOnlyConnection?: boolean } };
|
||||
expect(asset.requiredSchemaFingerprint).toBe(query.requiredSchemaFingerprint);
|
||||
expect(asset.safety).toMatchObject({ queryOnly: true, readOnlyConnection: true });
|
||||
expect(asset.statement).toMatch(/^(WITH|SELECT)\b/i);
|
||||
expect(asset.statement).not.toMatch(/;|\b(INSERT|UPDATE|DELETE|DROP|ALTER|CREATE|ATTACH)\b/i);
|
||||
|
||||
for (const schemaRef of [query.parameterSchemaRef, query.resultSchemaRef]) {
|
||||
expect(fs.existsSync(path.join(pluginDir, schemaRef))).toBe(true);
|
||||
}
|
||||
const resultSchema = JSON.parse(fs.readFileSync(path.join(pluginDir, query.resultSchemaRef), "utf8")) as { properties?: { rows?: { maxItems?: number } } };
|
||||
expect(resultSchema.properties?.rows?.maxItems).toBeLessThanOrEqual(query.maxRows);
|
||||
}
|
||||
});
|
||||
|
||||
it("requires SCUM schema probe targets to have generated Run workspace data targets", () => {
|
||||
const errors = validateTemporaryScumCompanionManifest((manifest) => {
|
||||
manifest.runtimeProfiles.dataTargets = [];
|
||||
@@ -238,7 +264,7 @@ describe("plugin manifest validation", () => {
|
||||
const fingerprint = `sha256:${"f".repeat(64)}`;
|
||||
const assetPaths = [
|
||||
"assets/scum-live/login-parser.json",
|
||||
"assets/scum-live/queries/players-read.json",
|
||||
"assets/scum-live/queries/fixture-players-read.json",
|
||||
"assets/scum-live/rcon/gift-grant.json",
|
||||
"assets/scum-live/mutations/profile-xml-patch.json",
|
||||
"assets/scum-live/map/island.png",
|
||||
|
||||
Reference in New Issue
Block a user