@codeyam/codeyam-cli 0.1.20 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/analyzer-template/.build-info.json +7 -7
- package/analyzer-template/log.txt +3 -3
- package/analyzer-template/package.json +1 -1
- package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +5 -1
- package/analyzer-template/packages/analyze/src/lib/files/analyze/findOrCreateEntity.ts +1 -0
- package/analyzer-template/packages/analyze/src/lib/files/analyzeChange.ts +4 -0
- package/analyzer-template/packages/analyze/src/lib/files/analyzeInitial.ts +4 -0
- package/analyzer-template/packages/aws/package.json +1 -1
- package/analyzer-template/packages/database/src/lib/loadEntity.ts +11 -4
- package/analyzer-template/packages/github/dist/database/src/lib/loadEntity.d.ts +4 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadEntity.d.ts.map +1 -1
- package/analyzer-template/packages/github/dist/database/src/lib/loadEntity.js +4 -4
- package/analyzer-template/packages/github/dist/database/src/lib/loadEntity.js.map +1 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.d.ts +3 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.d.ts.map +1 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.js +22 -1
- package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.js.map +1 -1
- package/analyzer-template/packages/utils/src/lib/fs/rsyncCopy.ts +27 -0
- package/codeyam-cli/src/commands/editor.js +185 -59
- package/codeyam-cli/src/commands/editor.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/editorAudit.test.js +630 -23
- package/codeyam-cli/src/utils/__tests__/editorAudit.test.js.map +1 -1
- package/codeyam-cli/src/utils/__tests__/registerScenarioResult.test.js +127 -0
- package/codeyam-cli/src/utils/__tests__/registerScenarioResult.test.js.map +1 -0
- package/codeyam-cli/src/utils/analyzer.js +8 -0
- package/codeyam-cli/src/utils/analyzer.js.map +1 -1
- package/codeyam-cli/src/utils/editorAudit.js +113 -12
- package/codeyam-cli/src/utils/editorAudit.js.map +1 -1
- package/codeyam-cli/src/utils/registerScenarioResult.js +52 -0
- package/codeyam-cli/src/utils/registerScenarioResult.js.map +1 -0
- package/codeyam-cli/src/webserver/app/lib/clientErrors.js +3 -0
- package/codeyam-cli/src/webserver/app/lib/clientErrors.js.map +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-save-scenario-data-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/api.editor-schema-l0sNRNKZ.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{cy-logo-cli-CCKUIm0S.svg → cy-logo-cli-CJzc4vOH.svg} +2 -2
- package/codeyam-cli/src/webserver/build/client/assets/cy-logo-cli-DODLxLcw.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/editor.entity.(_sha)-Dx-h1rJK.js +130 -0
- package/codeyam-cli/src/webserver/build/client/assets/editorPreview-NTuLi4Xg.js +41 -0
- package/codeyam-cli/src/webserver/build/client/assets/{entity._sha.scenarios._scenarioId.dev-KTQuL0aj.js → entity._sha.scenarios._scenarioId.dev-BA5L8bU-.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/{entity._sha.scenarios._scenarioId.fullscreen-C6eeL24i.js → entity._sha.scenarios._scenarioId.fullscreen-D4dmRgvO.js} +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/globals-BrPXT1iR.css +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/manifest-5025e428.js +1 -0
- package/codeyam-cli/src/webserver/build/client/assets/{root-BxUQigda.js → root-BCx1S8Z3.js} +26 -13
- package/codeyam-cli/src/webserver/build/server/assets/{analysisRunner-B_PsTAb1.js → analysisRunner-C1kjC9UJ.js} +1 -1
- package/codeyam-cli/src/webserver/build/server/assets/{index-CjLhfz6Z.js → index-C91yWWCI.js} +1 -1
- package/codeyam-cli/src/webserver/build/server/assets/{init-BEqlbI84.js → init-Dkas-RUS.js} +1 -1
- package/codeyam-cli/src/webserver/build/server/assets/server-build-pulXLTrG.js +640 -0
- package/codeyam-cli/src/webserver/build/server/index.js +1 -1
- package/codeyam-cli/src/webserver/build-info.json +5 -5
- package/codeyam-cli/src/webserver/terminalServer.js +10 -3
- package/codeyam-cli/src/webserver/terminalServer.js.map +1 -1
- package/package.json +1 -1
- package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js +4 -1
- package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js.map +1 -1
- package/packages/analyze/src/lib/files/analyze/findOrCreateEntity.js +1 -0
- package/packages/analyze/src/lib/files/analyze/findOrCreateEntity.js.map +1 -1
- package/packages/analyze/src/lib/files/analyzeChange.js +1 -0
- package/packages/analyze/src/lib/files/analyzeChange.js.map +1 -1
- package/packages/analyze/src/lib/files/analyzeInitial.js +1 -0
- package/packages/analyze/src/lib/files/analyzeInitial.js.map +1 -1
- package/packages/database/src/lib/loadEntity.js +4 -4
- package/packages/database/src/lib/loadEntity.js.map +1 -1
- package/packages/utils/src/lib/fs/rsyncCopy.js +22 -1
- package/packages/utils/src/lib/fs/rsyncCopy.js.map +1 -1
- package/codeyam-cli/src/webserver/build/client/assets/cy-logo-cli-DcX-ZS3p.js +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/editor.entity.(_sha)-DII1pg_z.js +0 -58
- package/codeyam-cli/src/webserver/build/client/assets/editorPreview-oepecPae.js +0 -41
- package/codeyam-cli/src/webserver/build/client/assets/globals-Yn9W3zp3.css +0 -1
- package/codeyam-cli/src/webserver/build/client/assets/manifest-cdf2c0a7.js +0 -1
- package/codeyam-cli/src/webserver/build/server/assets/server-build-YI63xTu4.js +0 -553
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Database from 'better-sqlite3';
|
|
2
2
|
import { Kysely, SqliteDialect } from 'kysely';
|
|
3
|
-
import { isComponent, classifyGlossaryEntries, computeAudit, filterGlossaryByChangeStatus, resolveAuditSessionScope, queryScenarioCounts, queryPageScenarioCounts, queryIncompleteEntities, queryMiscategorizedScenarios, queryUnassociatedScenarios, isOnlyIncompleteEntities, isAutoRemediable, identifyScenariosNeedingRecapture, detectDuplicateNames, } from "../editorAudit.js";
|
|
3
|
+
import { isComponent, classifyGlossaryEntries, computeAudit, filterGlossaryByChangeStatus, resolveAuditSessionScope, queryScenarioCounts, queryPageScenarioCounts, queryIncompleteEntities, queryMiscategorizedScenarios, queryUnassociatedScenarios, isOnlyIncompleteEntities, isOnlyPreExistingIncomplete, isAutoRemediable, identifyScenariosNeedingRecapture, detectDuplicateNames, } from "../editorAudit.js";
|
|
4
4
|
describe('editorAudit', () => {
|
|
5
5
|
describe('isComponent', () => {
|
|
6
6
|
it('should return true for JSX.Element return type', () => {
|
|
@@ -1466,6 +1466,279 @@ describe('editorAudit', () => {
|
|
|
1466
1466
|
expect(auditResult.summary.incompleteEntities).toBeUndefined();
|
|
1467
1467
|
});
|
|
1468
1468
|
});
|
|
1469
|
+
// ── filterToIncompleteFilePaths ──────────────────────────────────────
|
|
1470
|
+
describe('filterToIncompleteFilePaths', () => {
|
|
1471
|
+
// analyze-imports processes ALL file paths (~120 files) even when only
|
|
1472
|
+
// a few need analysis. This function filters to files that have no
|
|
1473
|
+
// entity with an analysis record.
|
|
1474
|
+
let db;
|
|
1475
|
+
let rawDb;
|
|
1476
|
+
const projectId = 'test-project-id';
|
|
1477
|
+
beforeEach(async () => {
|
|
1478
|
+
rawDb = new Database(':memory:');
|
|
1479
|
+
db = new Kysely({ dialect: new SqliteDialect({ database: rawDb }) });
|
|
1480
|
+
await db.schema
|
|
1481
|
+
.createTable('analyses')
|
|
1482
|
+
.addColumn('id', 'varchar', (col) => col.primaryKey())
|
|
1483
|
+
.addColumn('entity_sha', 'varchar')
|
|
1484
|
+
.addColumn('entity_name', 'varchar')
|
|
1485
|
+
.addColumn('project_id', 'varchar')
|
|
1486
|
+
.execute();
|
|
1487
|
+
await db.schema
|
|
1488
|
+
.createTable('entities')
|
|
1489
|
+
.addColumn('sha', 'varchar', (col) => col.primaryKey())
|
|
1490
|
+
.addColumn('name', 'varchar')
|
|
1491
|
+
.addColumn('entity_type', 'varchar')
|
|
1492
|
+
.addColumn('file_path', 'varchar')
|
|
1493
|
+
.execute();
|
|
1494
|
+
});
|
|
1495
|
+
afterEach(async () => {
|
|
1496
|
+
await db.destroy();
|
|
1497
|
+
});
|
|
1498
|
+
it('should exclude files that have an entity with an analysis', async () => {
|
|
1499
|
+
const { filterToIncompleteFilePaths } = require('../editorAudit');
|
|
1500
|
+
// Entity with analysis — skip
|
|
1501
|
+
await db
|
|
1502
|
+
.insertInto('entities')
|
|
1503
|
+
.values({
|
|
1504
|
+
sha: 'sha-header',
|
|
1505
|
+
name: 'Header',
|
|
1506
|
+
entity_type: 'visual',
|
|
1507
|
+
file_path: 'app/components/Header.tsx',
|
|
1508
|
+
})
|
|
1509
|
+
.execute();
|
|
1510
|
+
await db
|
|
1511
|
+
.insertInto('analyses')
|
|
1512
|
+
.values({
|
|
1513
|
+
id: 'a-1',
|
|
1514
|
+
entity_sha: 'sha-header',
|
|
1515
|
+
entity_name: 'Header',
|
|
1516
|
+
project_id: projectId,
|
|
1517
|
+
})
|
|
1518
|
+
.execute();
|
|
1519
|
+
// Entity without analysis — needs analysis
|
|
1520
|
+
await db
|
|
1521
|
+
.insertInto('entities')
|
|
1522
|
+
.values({
|
|
1523
|
+
sha: 'sha-rule',
|
|
1524
|
+
name: 'RuleBuilder',
|
|
1525
|
+
entity_type: 'visual',
|
|
1526
|
+
file_path: 'app/components/RuleBuilder.tsx',
|
|
1527
|
+
})
|
|
1528
|
+
.execute();
|
|
1529
|
+
const allFilePaths = [
|
|
1530
|
+
'app/components/Header.tsx',
|
|
1531
|
+
'app/components/RuleBuilder.tsx',
|
|
1532
|
+
'app/components/Footer.tsx', // no entity — needs analysis
|
|
1533
|
+
];
|
|
1534
|
+
const result = await filterToIncompleteFilePaths(db, projectId, allFilePaths);
|
|
1535
|
+
expect(result).toContain('app/components/RuleBuilder.tsx');
|
|
1536
|
+
expect(result).toContain('app/components/Footer.tsx');
|
|
1537
|
+
expect(result).not.toContain('app/components/Header.tsx');
|
|
1538
|
+
});
|
|
1539
|
+
it('should return all file paths when no entities exist yet', async () => {
|
|
1540
|
+
const { filterToIncompleteFilePaths } = require('../editorAudit');
|
|
1541
|
+
const filePaths = ['app/Foo.tsx', 'app/Bar.tsx'];
|
|
1542
|
+
const result = await filterToIncompleteFilePaths(db, projectId, filePaths);
|
|
1543
|
+
expect(result).toEqual(filePaths);
|
|
1544
|
+
});
|
|
1545
|
+
it('should return empty when all files have analyzed entities', async () => {
|
|
1546
|
+
const { filterToIncompleteFilePaths } = require('../editorAudit');
|
|
1547
|
+
await db
|
|
1548
|
+
.insertInto('entities')
|
|
1549
|
+
.values({
|
|
1550
|
+
sha: 'sha-a',
|
|
1551
|
+
name: 'CompA',
|
|
1552
|
+
entity_type: 'visual',
|
|
1553
|
+
file_path: 'app/CompA.tsx',
|
|
1554
|
+
})
|
|
1555
|
+
.execute();
|
|
1556
|
+
await db
|
|
1557
|
+
.insertInto('analyses')
|
|
1558
|
+
.values({
|
|
1559
|
+
id: 'a-1',
|
|
1560
|
+
entity_sha: 'sha-a',
|
|
1561
|
+
entity_name: 'CompA',
|
|
1562
|
+
project_id: projectId,
|
|
1563
|
+
})
|
|
1564
|
+
.execute();
|
|
1565
|
+
const result = await filterToIncompleteFilePaths(db, projectId, [
|
|
1566
|
+
'app/CompA.tsx',
|
|
1567
|
+
]);
|
|
1568
|
+
expect(result).toEqual([]);
|
|
1569
|
+
});
|
|
1570
|
+
it('should skip files with analysis even without scenarios', async () => {
|
|
1571
|
+
const { filterToIncompleteFilePaths } = require('../editorAudit');
|
|
1572
|
+
// Entity with analysis but NO scenarios — still complete
|
|
1573
|
+
await db
|
|
1574
|
+
.insertInto('entities')
|
|
1575
|
+
.values({
|
|
1576
|
+
sha: 'sha-util',
|
|
1577
|
+
name: 'utils',
|
|
1578
|
+
entity_type: 'library',
|
|
1579
|
+
file_path: 'app/lib/utils.ts',
|
|
1580
|
+
})
|
|
1581
|
+
.execute();
|
|
1582
|
+
await db
|
|
1583
|
+
.insertInto('analyses')
|
|
1584
|
+
.values({
|
|
1585
|
+
id: 'a-1',
|
|
1586
|
+
entity_sha: 'sha-util',
|
|
1587
|
+
entity_name: 'utils',
|
|
1588
|
+
project_id: projectId,
|
|
1589
|
+
})
|
|
1590
|
+
.execute();
|
|
1591
|
+
const result = await filterToIncompleteFilePaths(db, projectId, [
|
|
1592
|
+
'app/lib/utils.ts',
|
|
1593
|
+
]);
|
|
1594
|
+
expect(result).toEqual([]);
|
|
1595
|
+
});
|
|
1596
|
+
});
|
|
1597
|
+
// ── phantom entity SHAs ─────────────────────────────────────────────
|
|
1598
|
+
describe('queryIncompleteEntities with phantom entity SHAs', () => {
|
|
1599
|
+
// Root cause of the Margo/reader step-blocking bug:
|
|
1600
|
+
// Scenarios registered without component_path got a phantom entity_sha
|
|
1601
|
+
// computed from component_name alone. These SHAs have NO entity record
|
|
1602
|
+
// in the entities table and NO analyses. syncScenarioEntityShas can't
|
|
1603
|
+
// fix them (it skips scenarios without component_path). So they remain
|
|
1604
|
+
// "incomplete" forever, blocking step progression.
|
|
1605
|
+
//
|
|
1606
|
+
// Fix: queryIncompleteEntities should not report scenarios whose
|
|
1607
|
+
// entity_sha has no entity record — these are orphaned data, not
|
|
1608
|
+
// fixable by running analyze-imports.
|
|
1609
|
+
let db;
|
|
1610
|
+
let rawDb;
|
|
1611
|
+
const projectId = 'test-project-id';
|
|
1612
|
+
beforeEach(async () => {
|
|
1613
|
+
rawDb = new Database(':memory:');
|
|
1614
|
+
db = new Kysely({ dialect: new SqliteDialect({ database: rawDb }) });
|
|
1615
|
+
await db.schema
|
|
1616
|
+
.createTable('editor_scenarios')
|
|
1617
|
+
.addColumn('id', 'varchar', (col) => col.primaryKey())
|
|
1618
|
+
.addColumn('project_id', 'varchar', (col) => col.notNull())
|
|
1619
|
+
.addColumn('name', 'varchar', (col) => col.notNull())
|
|
1620
|
+
.addColumn('component_name', 'varchar')
|
|
1621
|
+
.addColumn('component_path', 'varchar')
|
|
1622
|
+
.addColumn('entity_sha', 'varchar')
|
|
1623
|
+
.addColumn('display_name', 'varchar')
|
|
1624
|
+
.addColumn('page_file_path', 'varchar')
|
|
1625
|
+
.addColumn('url', 'varchar')
|
|
1626
|
+
.addColumn('created_at', 'datetime')
|
|
1627
|
+
.addColumn('updated_at', 'datetime')
|
|
1628
|
+
.execute();
|
|
1629
|
+
await db.schema
|
|
1630
|
+
.createTable('analyses')
|
|
1631
|
+
.addColumn('id', 'varchar', (col) => col.primaryKey())
|
|
1632
|
+
.addColumn('entity_sha', 'varchar')
|
|
1633
|
+
.addColumn('entity_name', 'varchar')
|
|
1634
|
+
.addColumn('project_id', 'varchar')
|
|
1635
|
+
.execute();
|
|
1636
|
+
await db.schema
|
|
1637
|
+
.createTable('entities')
|
|
1638
|
+
.addColumn('sha', 'varchar', (col) => col.primaryKey())
|
|
1639
|
+
.addColumn('name', 'varchar')
|
|
1640
|
+
.addColumn('entity_type', 'varchar')
|
|
1641
|
+
.addColumn('file_path', 'varchar')
|
|
1642
|
+
.execute();
|
|
1643
|
+
});
|
|
1644
|
+
afterEach(async () => {
|
|
1645
|
+
await db.destroy();
|
|
1646
|
+
});
|
|
1647
|
+
it('should not report scenarios with phantom entity SHAs (no entity record exists)', async () => {
|
|
1648
|
+
// Real entity — has an entity record, analyses, and scenarios. Complete.
|
|
1649
|
+
await db
|
|
1650
|
+
.insertInto('entities')
|
|
1651
|
+
.values({
|
|
1652
|
+
sha: 'sha-real',
|
|
1653
|
+
name: 'RuleBuilder',
|
|
1654
|
+
entity_type: 'visual',
|
|
1655
|
+
file_path: 'app/components/RuleBuilder.tsx',
|
|
1656
|
+
})
|
|
1657
|
+
.execute();
|
|
1658
|
+
await db
|
|
1659
|
+
.insertInto('analyses')
|
|
1660
|
+
.values({
|
|
1661
|
+
id: 'a-1',
|
|
1662
|
+
entity_sha: 'sha-real',
|
|
1663
|
+
entity_name: 'RuleBuilder',
|
|
1664
|
+
project_id: projectId,
|
|
1665
|
+
})
|
|
1666
|
+
.execute();
|
|
1667
|
+
await db
|
|
1668
|
+
.insertInto('editor_scenarios')
|
|
1669
|
+
.values({
|
|
1670
|
+
id: 'sc-good',
|
|
1671
|
+
project_id: projectId,
|
|
1672
|
+
name: 'RuleBuilder - Empty',
|
|
1673
|
+
component_name: 'RuleBuilder',
|
|
1674
|
+
component_path: 'app/components/RuleBuilder.tsx',
|
|
1675
|
+
entity_sha: 'sha-real',
|
|
1676
|
+
created_at: '2026-03-16 23:00:00',
|
|
1677
|
+
})
|
|
1678
|
+
.execute();
|
|
1679
|
+
// Phantom entity — scenario points to a SHA that doesn't exist
|
|
1680
|
+
// in the entities table (registered without component_path).
|
|
1681
|
+
// No entity record, no analyses, unfixable by analyze-imports.
|
|
1682
|
+
await db
|
|
1683
|
+
.insertInto('editor_scenarios')
|
|
1684
|
+
.values({
|
|
1685
|
+
id: 'sc-phantom',
|
|
1686
|
+
project_id: projectId,
|
|
1687
|
+
name: 'Empty',
|
|
1688
|
+
component_name: 'RuleBuilder',
|
|
1689
|
+
component_path: null,
|
|
1690
|
+
entity_sha: 'sha-phantom-no-entity-record',
|
|
1691
|
+
created_at: '2026-03-16 22:00:00',
|
|
1692
|
+
})
|
|
1693
|
+
.execute();
|
|
1694
|
+
const incomplete = await queryIncompleteEntities(db, projectId, null);
|
|
1695
|
+
// Should NOT report phantom SHAs as incomplete — they can't be fixed
|
|
1696
|
+
// by running analyze-imports (no entity record exists to resolve).
|
|
1697
|
+
expect(incomplete).toHaveLength(0);
|
|
1698
|
+
});
|
|
1699
|
+
it('should still report real incomplete entities (entity exists but no analysis)', async () => {
|
|
1700
|
+
// Real entity without analysis — this IS a legitimate incomplete entity
|
|
1701
|
+
await db
|
|
1702
|
+
.insertInto('entities')
|
|
1703
|
+
.values({
|
|
1704
|
+
sha: 'sha-noanalysis',
|
|
1705
|
+
name: 'Footer',
|
|
1706
|
+
entity_type: 'visual',
|
|
1707
|
+
file_path: 'app/components/Footer.tsx',
|
|
1708
|
+
})
|
|
1709
|
+
.execute();
|
|
1710
|
+
await db
|
|
1711
|
+
.insertInto('editor_scenarios')
|
|
1712
|
+
.values({
|
|
1713
|
+
id: 'sc-1',
|
|
1714
|
+
project_id: projectId,
|
|
1715
|
+
name: 'Footer - Default',
|
|
1716
|
+
component_name: 'Footer',
|
|
1717
|
+
component_path: 'app/components/Footer.tsx',
|
|
1718
|
+
entity_sha: 'sha-noanalysis',
|
|
1719
|
+
created_at: '2026-03-16 23:00:00',
|
|
1720
|
+
})
|
|
1721
|
+
.execute();
|
|
1722
|
+
// Phantom scenario (shouldn't affect results)
|
|
1723
|
+
await db
|
|
1724
|
+
.insertInto('editor_scenarios')
|
|
1725
|
+
.values({
|
|
1726
|
+
id: 'sc-phantom',
|
|
1727
|
+
project_id: projectId,
|
|
1728
|
+
name: 'Footer - Alt',
|
|
1729
|
+
component_name: 'Footer',
|
|
1730
|
+
component_path: null,
|
|
1731
|
+
entity_sha: 'sha-phantom-does-not-exist',
|
|
1732
|
+
created_at: '2026-03-16 22:00:00',
|
|
1733
|
+
})
|
|
1734
|
+
.execute();
|
|
1735
|
+
const incomplete = await queryIncompleteEntities(db, projectId, null);
|
|
1736
|
+
// Should report Footer (real entity, no analysis) but NOT the phantom
|
|
1737
|
+
expect(incomplete).toHaveLength(1);
|
|
1738
|
+
expect(incomplete[0].name).toBe('Footer');
|
|
1739
|
+
expect(incomplete[0].entitySha).toBe('sha-noanalysis');
|
|
1740
|
+
});
|
|
1741
|
+
});
|
|
1469
1742
|
// ── queryMiscategorizedScenarios ─────────────────────────────────────
|
|
1470
1743
|
describe('queryMiscategorizedScenarios', () => {
|
|
1471
1744
|
let db;
|
|
@@ -1717,7 +1990,10 @@ describe('editorAudit', () => {
|
|
|
1717
1990
|
});
|
|
1718
1991
|
// ── isAutoRemediable ─────────────────────────────────────────────────
|
|
1719
1992
|
describe('isAutoRemediable', () => {
|
|
1720
|
-
|
|
1993
|
+
// isAutoRemediable always returns false — the audit never triggers
|
|
1994
|
+
// full analyze-imports inline. It takes minutes on large projects.
|
|
1995
|
+
// Only lightweight backfill is acceptable during audit.
|
|
1996
|
+
it('should return false even on first attempt with only incomplete entities', () => {
|
|
1721
1997
|
const result = isAutoRemediable({
|
|
1722
1998
|
componentsMissing: 0,
|
|
1723
1999
|
componentsWithErrors: 0,
|
|
@@ -1729,11 +2005,9 @@ describe('editorAudit', () => {
|
|
|
1729
2005
|
incompleteEntities: 3,
|
|
1730
2006
|
allPassing: false,
|
|
1731
2007
|
}, false);
|
|
1732
|
-
expect(result).toBe(
|
|
2008
|
+
expect(result).toBe(false);
|
|
1733
2009
|
});
|
|
1734
|
-
it('should return false on second attempt
|
|
1735
|
-
// This is the key fix: if we already tried analyze-imports and
|
|
1736
|
-
// entities are STILL incomplete, don't try again — report the failure
|
|
2010
|
+
it('should return false on second attempt', () => {
|
|
1737
2011
|
const result = isAutoRemediable({
|
|
1738
2012
|
componentsMissing: 0,
|
|
1739
2013
|
componentsWithErrors: 0,
|
|
@@ -2187,8 +2461,11 @@ describe('editorAudit', () => {
|
|
|
2187
2461
|
},
|
|
2188
2462
|
]);
|
|
2189
2463
|
});
|
|
2190
|
-
it('should
|
|
2191
|
-
// Scenario has entity_sha but entity record doesn't exist
|
|
2464
|
+
it('should skip phantom SHAs (entity_sha with no entity record)', async () => {
|
|
2465
|
+
// Scenario has entity_sha but entity record doesn't exist.
|
|
2466
|
+
// These are "phantom SHAs" created when scenarios were registered
|
|
2467
|
+
// without component_path — they can never be fixed by analyze-imports
|
|
2468
|
+
// and should not block audit progression.
|
|
2192
2469
|
await db
|
|
2193
2470
|
.insertInto('editor_scenarios')
|
|
2194
2471
|
.values({
|
|
@@ -2201,14 +2478,8 @@ describe('editorAudit', () => {
|
|
|
2201
2478
|
})
|
|
2202
2479
|
.execute();
|
|
2203
2480
|
const result = await queryIncompleteEntities(db, projectId, null);
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
entitySha: 'sha-ghost',
|
|
2207
|
-
name: 'GhostComponent',
|
|
2208
|
-
scenarioCount: 1,
|
|
2209
|
-
preExisting: false,
|
|
2210
|
-
},
|
|
2211
|
-
]);
|
|
2481
|
+
// Phantom SHAs are excluded — not reportable as incomplete
|
|
2482
|
+
expect(result).toEqual([]);
|
|
2212
2483
|
});
|
|
2213
2484
|
it('should detect incomplete entity whose scenario predates the session', async () => {
|
|
2214
2485
|
// Entity with no analyses, scenario created BEFORE session
|
|
@@ -2923,20 +3194,356 @@ describe('editorAudit', () => {
|
|
|
2923
3194
|
});
|
|
2924
3195
|
});
|
|
2925
3196
|
// ── isAutoRemediable with unassociatedScenarios ────────────────────
|
|
2926
|
-
describe('isAutoRemediable
|
|
2927
|
-
|
|
2928
|
-
|
|
3197
|
+
describe('isAutoRemediable always returns false (no inline full analysis)', () => {
|
|
3198
|
+
// Full analyze-imports takes minutes on large projects. The audit should
|
|
3199
|
+
// never trigger it — only the lightweight backfill path is acceptable.
|
|
3200
|
+
it('should return false for unassociatedScenarios only', () => {
|
|
3201
|
+
expect(isAutoRemediable({ unassociatedScenarios: 3 }, false)).toBe(false);
|
|
2929
3202
|
});
|
|
2930
|
-
it('should return
|
|
2931
|
-
expect(isAutoRemediable({ incompleteEntities: 1, unassociatedScenarios: 2 }, false)).toBe(
|
|
3203
|
+
it('should return false for incompleteEntities + unassociatedScenarios', () => {
|
|
3204
|
+
expect(isAutoRemediable({ incompleteEntities: 1, unassociatedScenarios: 2 }, false)).toBe(false);
|
|
2932
3205
|
});
|
|
2933
|
-
it('should return false
|
|
2934
|
-
expect(isAutoRemediable({ unassociatedScenarios: 2
|
|
3206
|
+
it('should return false even with no other failures', () => {
|
|
3207
|
+
expect(isAutoRemediable({ unassociatedScenarios: 2 }, false)).toBe(false);
|
|
2935
3208
|
});
|
|
2936
3209
|
it('should return false when already attempted', () => {
|
|
2937
3210
|
expect(isAutoRemediable({ unassociatedScenarios: 3 }, true)).toBe(false);
|
|
2938
3211
|
});
|
|
2939
3212
|
});
|
|
3213
|
+
describe('suggestedTestFile for functions without testFile', () => {
|
|
3214
|
+
it('should suggest conventional .test.ts path when testFile is undefined', () => {
|
|
3215
|
+
const result = computeAudit({
|
|
3216
|
+
components: [],
|
|
3217
|
+
functions: [
|
|
3218
|
+
{ name: 'useLibraryShell', filePath: 'app/library/context.tsx' },
|
|
3219
|
+
],
|
|
3220
|
+
scenarioCounts: {},
|
|
3221
|
+
testFileExistence: {},
|
|
3222
|
+
});
|
|
3223
|
+
expect(result.functions[0].suggestedTestFile).toBe('app/library/context.test.ts');
|
|
3224
|
+
expect(result.functions[0].status).toBe('missing');
|
|
3225
|
+
});
|
|
3226
|
+
it('should suggest .test.ts for .ts files', () => {
|
|
3227
|
+
const result = computeAudit({
|
|
3228
|
+
components: [],
|
|
3229
|
+
functions: [{ name: 'calculatePrice', filePath: 'app/lib/pricing.ts' }],
|
|
3230
|
+
scenarioCounts: {},
|
|
3231
|
+
testFileExistence: {},
|
|
3232
|
+
});
|
|
3233
|
+
expect(result.functions[0].suggestedTestFile).toBe('app/lib/pricing.test.ts');
|
|
3234
|
+
});
|
|
3235
|
+
it('should not set suggestedTestFile when testFile is already specified', () => {
|
|
3236
|
+
const result = computeAudit({
|
|
3237
|
+
components: [],
|
|
3238
|
+
functions: [
|
|
3239
|
+
{
|
|
3240
|
+
name: 'calculatePrice',
|
|
3241
|
+
filePath: 'app/lib/pricing.ts',
|
|
3242
|
+
testFile: 'app/lib/pricing.test.ts',
|
|
3243
|
+
},
|
|
3244
|
+
],
|
|
3245
|
+
scenarioCounts: {},
|
|
3246
|
+
testFileExistence: { 'app/lib/pricing.test.ts': true },
|
|
3247
|
+
});
|
|
3248
|
+
expect(result.functions[0].suggestedTestFile).toBeUndefined();
|
|
3249
|
+
});
|
|
3250
|
+
});
|
|
3251
|
+
describe('hint for missing components', () => {
|
|
3252
|
+
it('should hint that layout files need app-level scenarios', () => {
|
|
3253
|
+
const result = computeAudit({
|
|
3254
|
+
components: [
|
|
3255
|
+
{ name: 'LibraryLayout', filePath: 'app/library/layout.tsx' },
|
|
3256
|
+
],
|
|
3257
|
+
functions: [],
|
|
3258
|
+
scenarioCounts: {},
|
|
3259
|
+
testFileExistence: {},
|
|
3260
|
+
});
|
|
3261
|
+
expect(result.components[0].hint).toContain('layout');
|
|
3262
|
+
expect(result.components[0].hint).toContain('pageFilePath');
|
|
3263
|
+
});
|
|
3264
|
+
it('should hint that page files need app-level scenarios', () => {
|
|
3265
|
+
const result = computeAudit({
|
|
3266
|
+
components: [
|
|
3267
|
+
{ name: 'InboxPage', filePath: 'app/library/inbox/page.tsx' },
|
|
3268
|
+
],
|
|
3269
|
+
functions: [],
|
|
3270
|
+
scenarioCounts: {},
|
|
3271
|
+
testFileExistence: {},
|
|
3272
|
+
});
|
|
3273
|
+
expect(result.components[0].hint).toContain('page');
|
|
3274
|
+
expect(result.components[0].hint).toContain('pageFilePath');
|
|
3275
|
+
});
|
|
3276
|
+
it('should hint that regular components need isolation routes', () => {
|
|
3277
|
+
const result = computeAudit({
|
|
3278
|
+
components: [
|
|
3279
|
+
{ name: 'DrinkCard', filePath: 'app/components/DrinkCard.tsx' },
|
|
3280
|
+
],
|
|
3281
|
+
functions: [],
|
|
3282
|
+
scenarioCounts: {},
|
|
3283
|
+
testFileExistence: {},
|
|
3284
|
+
});
|
|
3285
|
+
expect(result.components[0].hint).toContain('isolated-components');
|
|
3286
|
+
});
|
|
3287
|
+
it('should not set hint when component has scenarios', () => {
|
|
3288
|
+
const result = computeAudit({
|
|
3289
|
+
components: [
|
|
3290
|
+
{ name: 'DrinkCard', filePath: 'app/components/DrinkCard.tsx' },
|
|
3291
|
+
],
|
|
3292
|
+
functions: [],
|
|
3293
|
+
scenarioCounts: { DrinkCard: 2 },
|
|
3294
|
+
testFileExistence: {},
|
|
3295
|
+
});
|
|
3296
|
+
expect(result.components[0].hint).toBeUndefined();
|
|
3297
|
+
});
|
|
3298
|
+
});
|
|
3299
|
+
describe('formatIncompleteEntityGuidance', () => {
|
|
3300
|
+
it('should include the entity name and scenario count', () => {
|
|
3301
|
+
const { formatIncompleteEntityGuidance } = require('../editorAudit');
|
|
3302
|
+
const result = formatIncompleteEntityGuidance({
|
|
3303
|
+
entitySha: 'abc123',
|
|
3304
|
+
name: 'RuleBuilder',
|
|
3305
|
+
scenarioCount: 5,
|
|
3306
|
+
preExisting: false,
|
|
3307
|
+
});
|
|
3308
|
+
expect(result).toContain('RuleBuilder');
|
|
3309
|
+
expect(result).toContain('5');
|
|
3310
|
+
});
|
|
3311
|
+
it('should tell Claude the exact fix command', () => {
|
|
3312
|
+
const { formatIncompleteEntityGuidance } = require('../editorAudit');
|
|
3313
|
+
const result = formatIncompleteEntityGuidance({
|
|
3314
|
+
entitySha: 'abc123',
|
|
3315
|
+
name: 'RuleBuilder',
|
|
3316
|
+
scenarioCount: 5,
|
|
3317
|
+
preExisting: false,
|
|
3318
|
+
});
|
|
3319
|
+
expect(result).toContain('codeyam editor analyze-imports');
|
|
3320
|
+
});
|
|
3321
|
+
it('should flag pre-existing issues as non-blocking', () => {
|
|
3322
|
+
const { formatIncompleteEntityGuidance } = require('../editorAudit');
|
|
3323
|
+
const result = formatIncompleteEntityGuidance({
|
|
3324
|
+
entitySha: 'abc123',
|
|
3325
|
+
name: 'RuleBuilder',
|
|
3326
|
+
scenarioCount: 5,
|
|
3327
|
+
preExisting: true,
|
|
3328
|
+
});
|
|
3329
|
+
expect(result).toContain('pre-existing');
|
|
3330
|
+
});
|
|
3331
|
+
it('should explain what incomplete means', () => {
|
|
3332
|
+
const { formatIncompleteEntityGuidance } = require('../editorAudit');
|
|
3333
|
+
const result = formatIncompleteEntityGuidance({
|
|
3334
|
+
entitySha: 'abc123',
|
|
3335
|
+
name: 'RuleBuilder',
|
|
3336
|
+
scenarioCount: 5,
|
|
3337
|
+
preExisting: false,
|
|
3338
|
+
});
|
|
3339
|
+
// Should explain the root cause, not just the symptom
|
|
3340
|
+
expect(result).toMatch(/scenario.*without.*import graph|import graph.*not.*built/i);
|
|
3341
|
+
});
|
|
3342
|
+
});
|
|
3343
|
+
describe('getIncompleteEntityFilePaths', () => {
|
|
3344
|
+
// The audit should auto-fix incomplete entities by running analysis on
|
|
3345
|
+
// just their specific file paths, not all 117+ files. This function
|
|
3346
|
+
// resolves entity SHAs to file paths for targeted analysis.
|
|
3347
|
+
let db;
|
|
3348
|
+
let rawDb;
|
|
3349
|
+
beforeEach(async () => {
|
|
3350
|
+
rawDb = new Database(':memory:');
|
|
3351
|
+
db = new Kysely({ dialect: new SqliteDialect({ database: rawDb }) });
|
|
3352
|
+
await db.schema
|
|
3353
|
+
.createTable('entities')
|
|
3354
|
+
.addColumn('sha', 'varchar', (col) => col.primaryKey())
|
|
3355
|
+
.addColumn('name', 'varchar')
|
|
3356
|
+
.addColumn('file_path', 'varchar')
|
|
3357
|
+
.addColumn('project_id', 'varchar')
|
|
3358
|
+
.addColumn('entity_type', 'varchar')
|
|
3359
|
+
.execute();
|
|
3360
|
+
});
|
|
3361
|
+
afterEach(() => {
|
|
3362
|
+
rawDb.close();
|
|
3363
|
+
});
|
|
3364
|
+
it('should resolve entity SHAs to file paths from the entities table', async () => {
|
|
3365
|
+
const { getIncompleteEntityFilePaths } = require('../editorAudit');
|
|
3366
|
+
await db
|
|
3367
|
+
.insertInto('entities')
|
|
3368
|
+
.values([
|
|
3369
|
+
{
|
|
3370
|
+
sha: 'sha-rule',
|
|
3371
|
+
name: 'RuleBuilder',
|
|
3372
|
+
file_path: 'app/components/RuleBuilder.tsx',
|
|
3373
|
+
project_id: 'p1',
|
|
3374
|
+
entity_type: 'component',
|
|
3375
|
+
},
|
|
3376
|
+
{
|
|
3377
|
+
sha: 'sha-row',
|
|
3378
|
+
name: 'ArticleTableRow',
|
|
3379
|
+
file_path: 'app/components/ArticleTableRow.tsx',
|
|
3380
|
+
project_id: 'p1',
|
|
3381
|
+
entity_type: 'component',
|
|
3382
|
+
},
|
|
3383
|
+
])
|
|
3384
|
+
.execute();
|
|
3385
|
+
const result = await getIncompleteEntityFilePaths(db, [
|
|
3386
|
+
{
|
|
3387
|
+
entitySha: 'sha-rule',
|
|
3388
|
+
name: 'RuleBuilder',
|
|
3389
|
+
scenarioCount: 5,
|
|
3390
|
+
preExisting: false,
|
|
3391
|
+
},
|
|
3392
|
+
{
|
|
3393
|
+
entitySha: 'sha-row',
|
|
3394
|
+
name: 'ArticleTableRow',
|
|
3395
|
+
scenarioCount: 2,
|
|
3396
|
+
preExisting: false,
|
|
3397
|
+
},
|
|
3398
|
+
]);
|
|
3399
|
+
expect(result).toContain('app/components/RuleBuilder.tsx');
|
|
3400
|
+
expect(result).toContain('app/components/ArticleTableRow.tsx');
|
|
3401
|
+
expect(result).toHaveLength(2);
|
|
3402
|
+
});
|
|
3403
|
+
it('should skip entities whose SHA is not in the entities table', async () => {
|
|
3404
|
+
const { getIncompleteEntityFilePaths } = require('../editorAudit');
|
|
3405
|
+
const result = await getIncompleteEntityFilePaths(db, [
|
|
3406
|
+
{
|
|
3407
|
+
entitySha: 'nonexistent-sha',
|
|
3408
|
+
name: 'Ghost',
|
|
3409
|
+
scenarioCount: 1,
|
|
3410
|
+
preExisting: false,
|
|
3411
|
+
},
|
|
3412
|
+
]);
|
|
3413
|
+
expect(result).toHaveLength(0);
|
|
3414
|
+
});
|
|
3415
|
+
it('should deduplicate file paths', async () => {
|
|
3416
|
+
const { getIncompleteEntityFilePaths } = require('../editorAudit');
|
|
3417
|
+
await db
|
|
3418
|
+
.insertInto('entities')
|
|
3419
|
+
.values([
|
|
3420
|
+
{
|
|
3421
|
+
sha: 'sha-v1',
|
|
3422
|
+
name: 'Foo',
|
|
3423
|
+
file_path: 'app/Foo.tsx',
|
|
3424
|
+
project_id: 'p1',
|
|
3425
|
+
entity_type: 'component',
|
|
3426
|
+
},
|
|
3427
|
+
{
|
|
3428
|
+
sha: 'sha-v2',
|
|
3429
|
+
name: 'Foo',
|
|
3430
|
+
file_path: 'app/Foo.tsx',
|
|
3431
|
+
project_id: 'p1',
|
|
3432
|
+
entity_type: 'component',
|
|
3433
|
+
},
|
|
3434
|
+
])
|
|
3435
|
+
.execute();
|
|
3436
|
+
const result = await getIncompleteEntityFilePaths(db, [
|
|
3437
|
+
{
|
|
3438
|
+
entitySha: 'sha-v1',
|
|
3439
|
+
name: 'Foo',
|
|
3440
|
+
scenarioCount: 3,
|
|
3441
|
+
preExisting: false,
|
|
3442
|
+
},
|
|
3443
|
+
{
|
|
3444
|
+
entitySha: 'sha-v2',
|
|
3445
|
+
name: 'Foo',
|
|
3446
|
+
scenarioCount: 1,
|
|
3447
|
+
preExisting: false,
|
|
3448
|
+
},
|
|
3449
|
+
]);
|
|
3450
|
+
expect(result).toEqual(['app/Foo.tsx']);
|
|
3451
|
+
});
|
|
3452
|
+
});
|
|
3453
|
+
describe('isAutoRemediable never triggers full analysis', () => {
|
|
3454
|
+
// The audit must NEVER run handleAnalyzeImports inline — it takes minutes
|
|
3455
|
+
// for large projects. Auto-remediation should only do the lightweight
|
|
3456
|
+
// entity SHA backfill. isAutoRemediable is now always false; the callers
|
|
3457
|
+
// use needsBackfillOnly for the fast path instead.
|
|
3458
|
+
it('should always return false regardless of summary state', () => {
|
|
3459
|
+
expect(isAutoRemediable({ incompleteEntities: 5 }, false)).toBe(false);
|
|
3460
|
+
expect(isAutoRemediable({ unassociatedScenarios: 3 }, false)).toBe(false);
|
|
3461
|
+
expect(isAutoRemediable({ incompleteEntities: 1, unassociatedScenarios: 2 }, false)).toBe(false);
|
|
3462
|
+
});
|
|
3463
|
+
});
|
|
3464
|
+
// ── isOnlyPreExistingIncomplete ─────────────────────────────────────
|
|
3465
|
+
describe('isOnlyPreExistingIncomplete', () => {
|
|
3466
|
+
it('should return true when all incomplete entities are pre-existing and no other failures', () => {
|
|
3467
|
+
expect(isOnlyPreExistingIncomplete({
|
|
3468
|
+
incompleteEntities: 2,
|
|
3469
|
+
preExistingIncompleteEntities: 2,
|
|
3470
|
+
componentsMissing: 0,
|
|
3471
|
+
componentsWithErrors: 0,
|
|
3472
|
+
functionsFailing: 0,
|
|
3473
|
+
functionsNameMismatch: 0,
|
|
3474
|
+
functionsMissing: 0,
|
|
3475
|
+
missingFromGlossary: 0,
|
|
3476
|
+
miscategorizedScenarios: 0,
|
|
3477
|
+
scenariosNeedingRecapture: 0,
|
|
3478
|
+
}, [
|
|
3479
|
+
{
|
|
3480
|
+
entitySha: 'a',
|
|
3481
|
+
name: 'RuleBuilder',
|
|
3482
|
+
scenarioCount: 5,
|
|
3483
|
+
preExisting: true,
|
|
3484
|
+
},
|
|
3485
|
+
{
|
|
3486
|
+
entitySha: 'b',
|
|
3487
|
+
name: 'ArticleTableRow',
|
|
3488
|
+
scenarioCount: 2,
|
|
3489
|
+
preExisting: true,
|
|
3490
|
+
},
|
|
3491
|
+
])).toBe(true);
|
|
3492
|
+
});
|
|
3493
|
+
it('should return false when some incomplete entities are NOT pre-existing', () => {
|
|
3494
|
+
expect(isOnlyPreExistingIncomplete({
|
|
3495
|
+
incompleteEntities: 2,
|
|
3496
|
+
preExistingIncompleteEntities: 1,
|
|
3497
|
+
componentsMissing: 0,
|
|
3498
|
+
componentsWithErrors: 0,
|
|
3499
|
+
functionsFailing: 0,
|
|
3500
|
+
functionsNameMismatch: 0,
|
|
3501
|
+
functionsMissing: 0,
|
|
3502
|
+
missingFromGlossary: 0,
|
|
3503
|
+
miscategorizedScenarios: 0,
|
|
3504
|
+
scenariosNeedingRecapture: 0,
|
|
3505
|
+
}, [
|
|
3506
|
+
{
|
|
3507
|
+
entitySha: 'a',
|
|
3508
|
+
name: 'RuleBuilder',
|
|
3509
|
+
scenarioCount: 5,
|
|
3510
|
+
preExisting: true,
|
|
3511
|
+
},
|
|
3512
|
+
{
|
|
3513
|
+
entitySha: 'b',
|
|
3514
|
+
name: 'NewComponent',
|
|
3515
|
+
scenarioCount: 1,
|
|
3516
|
+
preExisting: false,
|
|
3517
|
+
},
|
|
3518
|
+
])).toBe(false);
|
|
3519
|
+
});
|
|
3520
|
+
it('should return false when there are other failures besides incomplete entities', () => {
|
|
3521
|
+
expect(isOnlyPreExistingIncomplete({
|
|
3522
|
+
incompleteEntities: 2,
|
|
3523
|
+
preExistingIncompleteEntities: 2,
|
|
3524
|
+
componentsMissing: 1,
|
|
3525
|
+
}, [
|
|
3526
|
+
{
|
|
3527
|
+
entitySha: 'a',
|
|
3528
|
+
name: 'RuleBuilder',
|
|
3529
|
+
scenarioCount: 5,
|
|
3530
|
+
preExisting: true,
|
|
3531
|
+
},
|
|
3532
|
+
{
|
|
3533
|
+
entitySha: 'b',
|
|
3534
|
+
name: 'ArticleTableRow',
|
|
3535
|
+
scenarioCount: 2,
|
|
3536
|
+
preExisting: true,
|
|
3537
|
+
},
|
|
3538
|
+
])).toBe(false);
|
|
3539
|
+
});
|
|
3540
|
+
it('should return false when incomplete entities array is empty', () => {
|
|
3541
|
+
expect(isOnlyPreExistingIncomplete({ incompleteEntities: 0 }, [])).toBe(false);
|
|
3542
|
+
});
|
|
3543
|
+
it('should return false when incomplete entities array is missing', () => {
|
|
3544
|
+
expect(isOnlyPreExistingIncomplete({ incompleteEntities: 2, preExistingIncompleteEntities: 2 }, undefined)).toBe(false);
|
|
3545
|
+
});
|
|
3546
|
+
});
|
|
2940
3547
|
describe('isOnlyIncompleteEntities with unassociatedScenarios', () => {
|
|
2941
3548
|
it('should return true when only unassociatedScenarios present', () => {
|
|
2942
3549
|
expect(isOnlyIncompleteEntities({ unassociatedScenarios: 5 })).toBe(true);
|