mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 05:16:23 -06:00
fix(state): refresh migrated agent registry schema
This commit is contained in:
@@ -199,6 +199,34 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
describe("legacy media persistence doctor migration", () => {
|
||||
it("refreshes a registry-owned v16 database after structural convergence", () => {
|
||||
const stateDir = makeTempDir(tempDirs, "media-persistence-registry-v16-");
|
||||
const env = { OPENCLAW_STATE_DIR: stateDir };
|
||||
const opened = openOpenClawAgentDatabase({ agentId: "main", env });
|
||||
const databasePath = opened.path;
|
||||
closeOpenClawAgentDatabasesForTest();
|
||||
const { DatabaseSync } = requireNodeSqlite();
|
||||
const database = new DatabaseSync(databasePath);
|
||||
database.exec(`PRAGMA user_version = ${OPENCLAW_AGENT_MEDIA_PERSISTENCE_SCHEMA_VERSION};`);
|
||||
database
|
||||
.prepare("UPDATE schema_meta SET schema_version = ? WHERE meta_key = 'primary'")
|
||||
.run(OPENCLAW_AGENT_MEDIA_PERSISTENCE_SCHEMA_VERSION);
|
||||
database.close();
|
||||
registerOpenClawAgentDatabase({
|
||||
agentId: "main",
|
||||
env,
|
||||
path: databasePath,
|
||||
schemaVersion: OPENCLAW_AGENT_MEDIA_PERSISTENCE_SCHEMA_VERSION,
|
||||
});
|
||||
|
||||
expect(migrateLegacyMediaPersistence({ env }).warnings).toEqual([]);
|
||||
expect(listOpenClawRegisteredAgentDatabases({ env })).toEqual([
|
||||
expect.objectContaining({
|
||||
schemaVersion: OPENCLAW_AGENT_SCHEMA_VERSION,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("canonicalizes assistant media at the generic transcript append owner", () => {
|
||||
const stateDir = makeTempDir(tempDirs, "media-persistence-append-");
|
||||
const env = { OPENCLAW_STATE_DIR: stateDir };
|
||||
|
||||
@@ -402,14 +402,15 @@ function migrateAgentDatabase(params: {
|
||||
const changedSessions = planned.filter((session) => session.changed);
|
||||
const versionAdvanced = userVersion === PREVIOUS_MEDIA_SCHEMA_VERSION;
|
||||
if (!versionAdvanced && changedSessions.length === 0 && changedTrajectoryRows.length === 0) {
|
||||
const schemaVersion = convergeCurrentAgentSchema({
|
||||
agentId: params.agentId,
|
||||
database,
|
||||
pathname: params.pathname,
|
||||
});
|
||||
return {
|
||||
rewrittenSessions: 0,
|
||||
rewrittenTrajectoryRows: 0,
|
||||
schemaVersion: convergeCurrentAgentSchema({
|
||||
agentId: params.agentId,
|
||||
database,
|
||||
pathname: params.pathname,
|
||||
}),
|
||||
schemaVersion,
|
||||
versionAdvanced: false,
|
||||
};
|
||||
}
|
||||
@@ -669,14 +670,12 @@ export function migrateLegacyMediaPersistence(
|
||||
: undefined,
|
||||
pathname,
|
||||
});
|
||||
if (entry.source !== "registry" || result.versionAdvanced) {
|
||||
registerOpenClawAgentDatabase({
|
||||
agentId: entry.agentId,
|
||||
env,
|
||||
path: pathname,
|
||||
schemaVersion: result.schemaVersion,
|
||||
});
|
||||
}
|
||||
registerOpenClawAgentDatabase({
|
||||
agentId: entry.agentId,
|
||||
env,
|
||||
path: pathname,
|
||||
schemaVersion: result.schemaVersion,
|
||||
});
|
||||
if (
|
||||
result.versionAdvanced ||
|
||||
result.rewrittenSessions > 0 ||
|
||||
|
||||
Reference in New Issue
Block a user