|
6 | 6 | dataModelChangeFromPullFilesForTest, |
7 | 7 | renderReviewCommentFromReport, |
8 | 8 | reviewAutomationMarkersFromReport, |
| 9 | + sqliteSchemaChangeFromPullFilesForTest, |
9 | 10 | } from "../dist/clawsweeper.js"; |
10 | 11 | import { reportFrontMatter } from "./helpers.ts"; |
11 | 12 |
|
@@ -294,6 +295,95 @@ test("data model detector ignores query-only and non-semantic docs changes", () |
294 | 295 | assert.deepEqual(detection, { change: false, surfaces: [] }); |
295 | 296 | }); |
296 | 297 |
|
| 298 | +test("SQLite schema detector finds production table changes and ignores non-schema SQL", () => { |
| 299 | + const detection = sqliteSchemaChangeFromPullFilesForTest({ |
| 300 | + pullFiles: [ |
| 301 | + { |
| 302 | + filename: "packages/memory-host-sdk/src/host/memory-schema-base.ts", |
| 303 | + patch: |
| 304 | + "@@\n CREATE TABLE IF NOT EXISTS memory_index_chunks (\n id TEXT PRIMARY KEY,\n+ source_kind TEXT NOT NULL,\n );", |
| 305 | + }, |
| 306 | + { |
| 307 | + filename: "src/transcripts/sqlite-schema.ts", |
| 308 | + patch: |
| 309 | + "@@\n+CREATE TABLE IF NOT EXISTS meeting_transcript_summaries (\n+ id TEXT PRIMARY KEY\n+);", |
| 310 | + }, |
| 311 | + { |
| 312 | + filename: "src/memory/search.ts", |
| 313 | + patch: "@@\n+ return db.prepare('SELECT * FROM memory_index_chunks').all();", |
| 314 | + }, |
| 315 | + { |
| 316 | + filename: "src/memory/manager-db.test.ts", |
| 317 | + patch: "@@\n+ db.exec('CREATE TABLE fixture_rows (id TEXT PRIMARY KEY)');", |
| 318 | + }, |
| 319 | + { |
| 320 | + filename: "docs/storage.md", |
| 321 | + patch: "@@\n+CREATE TABLE example_rows (id TEXT PRIMARY KEY);", |
| 322 | + }, |
| 323 | + ], |
| 324 | + }); |
| 325 | + |
| 326 | + assert.deepEqual(detection, { |
| 327 | + change: true, |
| 328 | + files: [ |
| 329 | + "packages/memory-host-sdk/src/host/memory-schema-base.ts", |
| 330 | + "src/transcripts/sqlite-schema.ts", |
| 331 | + ], |
| 332 | + }); |
| 333 | +}); |
| 334 | + |
| 335 | +test("SQLite schema warning is visible for table changes and absent otherwise", () => { |
| 336 | + const reportBody = ` |
| 337 | +
|
| 338 | +## Summary |
| 339 | +
|
| 340 | +Keep this PR open for maintainer review. |
| 341 | +
|
| 342 | +## What This Changes |
| 343 | +
|
| 344 | +Adds a column to the persisted memory index. |
| 345 | +`; |
| 346 | + const warningComment = renderReviewCommentFromReport( |
| 347 | + `${reportFrontMatter({ |
| 348 | + repository: "openclaw/openclaw", |
| 349 | + type: "pull_request", |
| 350 | + number: "74464", |
| 351 | + decision: "keep_open", |
| 352 | + close_reason: "none", |
| 353 | + work_candidate: "none", |
| 354 | + sqlite_schema_change: "true", |
| 355 | + sqlite_schema_files: JSON.stringify([ |
| 356 | + "packages/memory-host-sdk/src/host/memory-schema-base.ts", |
| 357 | + ]), |
| 358 | + })}${reportBody}`, |
| 359 | + "none", |
| 360 | + ); |
| 361 | + const ordinaryComment = renderReviewCommentFromReport( |
| 362 | + `${reportFrontMatter({ |
| 363 | + repository: "openclaw/openclaw", |
| 364 | + type: "pull_request", |
| 365 | + number: "74465", |
| 366 | + decision: "keep_open", |
| 367 | + close_reason: "none", |
| 368 | + work_candidate: "none", |
| 369 | + sqlite_schema_change: "false", |
| 370 | + sqlite_schema_files: JSON.stringify([]), |
| 371 | + })}${reportBody}`, |
| 372 | + "none", |
| 373 | + ); |
| 374 | + |
| 375 | + assert.match(warningComment, /> \[!WARNING\]/); |
| 376 | + assert.match(warningComment, /SQLite table change/); |
| 377 | + assert.match(warningComment, /`packages\/memory-host-sdk\/src\/host\/memory-schema-base\.ts`/); |
| 378 | + assert.match(warningComment, /Prefer a design that avoids changing persisted SQLite tables/); |
| 379 | + assert.ok( |
| 380 | + warningComment.indexOf("SQLite table change") < |
| 381 | + warningComment.indexOf("<summary><strong>Agent review details</strong></summary>"), |
| 382 | + ); |
| 383 | + assert.doesNotMatch(ordinaryComment, /SQLite table change/); |
| 384 | + assert.doesNotMatch(ordinaryComment, /\[!WARNING\]/); |
| 385 | +}); |
| 386 | + |
297 | 387 | test("data model detector flags path-hinted persisted field declarations", () => { |
298 | 388 | const detection = dataModelChangeFromPullFilesForTest({ |
299 | 389 | pullFiles: [ |
|
0 commit comments