fix(page-data): grant agent role set permission

This commit is contained in:
john
2026-07-17 09:32:31 +08:00
parent 331a863288
commit a5d109d585
6 changed files with 81 additions and 2 deletions
+10
View File
@@ -5,6 +5,7 @@ import path from 'node:path';
import test from 'node:test';
import {
buildControlSchemaSql,
buildEnsureCurrentUserCanSetRoleSql,
buildPostgresTableSql,
buildPostgresCheckSql,
buildPostgresForeignKeySql,
@@ -44,12 +45,21 @@ test('provision SQL creates isolated no-login roles and safety limits', () => {
assert.match(sql, /CREATE ROLE "ms_u_ecc1c649fff7_owner" NOLOGIN/);
assert.match(sql, /CREATE ROLE "ms_u_ecc1c649fff7_agent" NOLOGIN NOSUPERUSER NOCREATEDB NOCREATEROLE/);
assert.match(sql, /pg_auth_members/);
assert.match(sql, /r\.rolname = 'ms_u_ecc1c649fff7_agent'.*am\.set_option/s);
assert.match(sql, /GRANT %I TO %I WITH INHERIT FALSE, SET TRUE/);
assert.match(sql, /REVOKE ALL ON SCHEMA "u_ecc1c649fff74361a243a69b460cc407" FROM PUBLIC/);
assert.match(sql, /statement_timeout = '30s'/);
assert.match(sql, /NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATION/);
assert.doesNotMatch(sql, /temp_file_limit/);
});
test('agent role reconciliation requires SET without inherited privileges', () => {
const sql = buildEnsureCurrentUserCanSetRoleSql('ms_u_ecc1c649fff7_agent');
assert.match(sql, /m\.rolname = CURRENT_USER AND am\.set_option/);
assert.match(sql, /WITH INHERIT FALSE, SET TRUE/);
assert.doesNotMatch(sql, /WITH INHERIT TRUE/);
});
test('SQLite types and defaults map to conservative PostgreSQL equivalents', () => {
assert.equal(mapSqliteTypeToPostgres({ type: 'INTEGER', pk: 1 }), 'bigint GENERATED BY DEFAULT AS IDENTITY');
assert.equal(mapSqliteTypeToPostgres({ type: 'REAL', pk: 0 }), 'double precision');