@elvis1513/auto-coding-skill 4.2.2 → 4.2.4
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/README.md +31 -4
- package/cli/assets/managed-install.json +1 -1
- package/cli/assets/skill/SKILL.md +4 -5
- package/cli/assets/skill/data/policies/workflow-migrations-v1.json +2 -2
- package/cli/assets/skill/data/templates/ENGINEERING.md +3 -2
- package/cli/assets/skill/data/templates/bridges/AGENTS.md +5 -5
- package/cli/assets/skill/scripts/ap.py +701 -21
- package/cli/tests/ap_profiles_test.py +612 -0
- package/cli/tests/index.test.js +63 -18
- package/package.json +1 -1
|
@@ -10,6 +10,7 @@ import os
|
|
|
10
10
|
import subprocess
|
|
11
11
|
import sys
|
|
12
12
|
import tempfile
|
|
13
|
+
import time
|
|
13
14
|
import tomllib
|
|
14
15
|
import unittest
|
|
15
16
|
from pathlib import Path
|
|
@@ -1396,6 +1397,617 @@ class AutoCodingProfileTests(unittest.TestCase):
|
|
|
1396
1397
|
with self.assertRaises(APError):
|
|
1397
1398
|
ap.cmd_structure_check(args)
|
|
1398
1399
|
|
|
1400
|
+
def test_structure_block_warnings_matrix(self) -> None:
|
|
1401
|
+
cases = [
|
|
1402
|
+
("blocking", True, True),
|
|
1403
|
+
("blocking", False, False),
|
|
1404
|
+
("advisory", True, False),
|
|
1405
|
+
]
|
|
1406
|
+
for enforcement, configured_block_warnings, should_block in cases:
|
|
1407
|
+
with self.subTest(
|
|
1408
|
+
enforcement=enforcement,
|
|
1409
|
+
block_warnings=configured_block_warnings,
|
|
1410
|
+
):
|
|
1411
|
+
cfg = base_config()
|
|
1412
|
+
cfg["structure"] = {
|
|
1413
|
+
"enabled": True,
|
|
1414
|
+
"enforcement": enforcement,
|
|
1415
|
+
"block_warnings": configured_block_warnings,
|
|
1416
|
+
"max_file_lines_warn": 4,
|
|
1417
|
+
"max_file_lines_block": 50,
|
|
1418
|
+
"max_function_lines_warn": 4,
|
|
1419
|
+
"max_added_lines_to_large_file": 50,
|
|
1420
|
+
"layer_rules": {"enabled": False},
|
|
1421
|
+
}
|
|
1422
|
+
cfg["optimization"] = {"require_baseline_for_global_review": False}
|
|
1423
|
+
repo, _ = self.make_repo("src/large.py", cfg)
|
|
1424
|
+
(repo / "src" / "large.py").write_text(
|
|
1425
|
+
"def oversized():\n"
|
|
1426
|
+
" value = 1\n"
|
|
1427
|
+
" value += 1\n"
|
|
1428
|
+
" value += 1\n"
|
|
1429
|
+
" return value\n"
|
|
1430
|
+
"tail = 1\n",
|
|
1431
|
+
encoding="utf-8",
|
|
1432
|
+
)
|
|
1433
|
+
output = io.StringIO()
|
|
1434
|
+
args = argparse.Namespace(
|
|
1435
|
+
repo=str(repo), scope="changed", base="", json=True
|
|
1436
|
+
)
|
|
1437
|
+
with mock.patch.object(ap, "_record_evidence"), contextlib.redirect_stdout(output):
|
|
1438
|
+
if should_block:
|
|
1439
|
+
with self.assertRaisesRegex(APError, "2 blocking issue"):
|
|
1440
|
+
ap.cmd_structure_check(args)
|
|
1441
|
+
else:
|
|
1442
|
+
ap.cmd_structure_check(args)
|
|
1443
|
+
|
|
1444
|
+
result = json.loads(output.getvalue())
|
|
1445
|
+
self.assertIs(should_block, result["block_warnings"])
|
|
1446
|
+
if should_block:
|
|
1447
|
+
self.assertEqual(2, len(result["blocking"]))
|
|
1448
|
+
else:
|
|
1449
|
+
self.assertEqual([], result["blocking"])
|
|
1450
|
+
self.assertEqual(2, len(result["warnings"]))
|
|
1451
|
+
|
|
1452
|
+
def test_structure_block_warnings_keeps_accepted_debt_size_findings_advisory(self) -> None:
|
|
1453
|
+
cfg = base_config()
|
|
1454
|
+
cfg["structure"] = {
|
|
1455
|
+
"enabled": True,
|
|
1456
|
+
"enforcement": "blocking",
|
|
1457
|
+
"block_warnings": True,
|
|
1458
|
+
"max_file_lines_warn": 4,
|
|
1459
|
+
"max_file_lines_block": 50,
|
|
1460
|
+
"max_function_lines_warn": 4,
|
|
1461
|
+
"max_added_lines_to_large_file": 50,
|
|
1462
|
+
"accepted_debt_paths": ["src/accepted.py"],
|
|
1463
|
+
"layer_rules": {"enabled": False},
|
|
1464
|
+
}
|
|
1465
|
+
cfg["optimization"] = {"require_baseline_for_global_review": False}
|
|
1466
|
+
repo, _ = self.make_repo("src/accepted.py", cfg)
|
|
1467
|
+
(repo / "src" / "accepted.py").write_text(
|
|
1468
|
+
"def accepted_debt():\n"
|
|
1469
|
+
" value = 1\n"
|
|
1470
|
+
" value += 1\n"
|
|
1471
|
+
" value += 1\n"
|
|
1472
|
+
" return value\n"
|
|
1473
|
+
"tail = 1\n",
|
|
1474
|
+
encoding="utf-8",
|
|
1475
|
+
)
|
|
1476
|
+
output = io.StringIO()
|
|
1477
|
+
with mock.patch.object(ap, "_record_evidence"), contextlib.redirect_stdout(output):
|
|
1478
|
+
ap.cmd_structure_check(
|
|
1479
|
+
argparse.Namespace(
|
|
1480
|
+
repo=str(repo), scope="changed", base="", json=True
|
|
1481
|
+
)
|
|
1482
|
+
)
|
|
1483
|
+
|
|
1484
|
+
result = json.loads(output.getvalue())
|
|
1485
|
+
self.assertIs(True, result["block_warnings"])
|
|
1486
|
+
self.assertEqual([], result["blocking"])
|
|
1487
|
+
self.assertEqual(2, len(result["warnings"]))
|
|
1488
|
+
|
|
1489
|
+
def test_changed_scope_light_gate_blocks_promoted_structure_warnings(self) -> None:
|
|
1490
|
+
cfg = base_config()
|
|
1491
|
+
cfg["structure"] = {
|
|
1492
|
+
"enabled": True,
|
|
1493
|
+
"enforcement": "blocking",
|
|
1494
|
+
"block_warnings": True,
|
|
1495
|
+
"max_file_lines_warn": 3,
|
|
1496
|
+
"max_file_lines_block": 50,
|
|
1497
|
+
"max_function_lines_warn": 0,
|
|
1498
|
+
"max_added_lines_to_large_file": 50,
|
|
1499
|
+
"layer_rules": {"enabled": False},
|
|
1500
|
+
}
|
|
1501
|
+
cfg["optimization"] = {"require_baseline_for_global_review": False}
|
|
1502
|
+
repo, _ = self.make_repo("src/warn-only.py", cfg)
|
|
1503
|
+
(repo / "src" / "warn-only.py").write_text(
|
|
1504
|
+
"one\ntwo\nthree\nfour\n",
|
|
1505
|
+
encoding="utf-8",
|
|
1506
|
+
)
|
|
1507
|
+
|
|
1508
|
+
with mock.patch.object(ap, "_record_evidence"):
|
|
1509
|
+
with self.assertRaisesRegex(APError, "structure-check failed"):
|
|
1510
|
+
ap.cmd_light_gate(
|
|
1511
|
+
argparse.Namespace(
|
|
1512
|
+
repo=str(repo),
|
|
1513
|
+
scope="changed",
|
|
1514
|
+
profile="",
|
|
1515
|
+
mode="dev",
|
|
1516
|
+
base="",
|
|
1517
|
+
explain=False,
|
|
1518
|
+
)
|
|
1519
|
+
)
|
|
1520
|
+
|
|
1521
|
+
def test_doctor_validates_structure_block_warnings_type_and_advises_on_no_effect(self) -> None:
|
|
1522
|
+
cfg = base_config()
|
|
1523
|
+
cfg["structure"] = {
|
|
1524
|
+
"enabled": True,
|
|
1525
|
+
"enforcement": "blocking",
|
|
1526
|
+
"block_warnings": "true",
|
|
1527
|
+
}
|
|
1528
|
+
repo, _ = self.make_repo(config=cfg)
|
|
1529
|
+
with self.assertRaisesRegex(
|
|
1530
|
+
APError,
|
|
1531
|
+
"structure.block_warnings must be a boolean",
|
|
1532
|
+
):
|
|
1533
|
+
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
1534
|
+
|
|
1535
|
+
cfg = base_config()
|
|
1536
|
+
cfg["structure"] = {
|
|
1537
|
+
"enabled": True,
|
|
1538
|
+
"enforcement": "advisory",
|
|
1539
|
+
"block_warnings": True,
|
|
1540
|
+
}
|
|
1541
|
+
repo, _ = self.make_repo(config=cfg)
|
|
1542
|
+
output = io.StringIO()
|
|
1543
|
+
with mock.patch.object(ap, "_record_evidence"), contextlib.redirect_stdout(output):
|
|
1544
|
+
ap.cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
1545
|
+
self.assertIn(
|
|
1546
|
+
"structure.block_warnings has no effect unless structure.enforcement=blocking",
|
|
1547
|
+
output.getvalue(),
|
|
1548
|
+
)
|
|
1549
|
+
self.assertIn("[doctor] OK", output.getvalue())
|
|
1550
|
+
|
|
1551
|
+
def test_java_and_kotlin_semicolon_imports_trigger_layer_rules(self) -> None:
|
|
1552
|
+
structure_cfg = {
|
|
1553
|
+
"layer_rules": {
|
|
1554
|
+
"enabled": True,
|
|
1555
|
+
"block": True,
|
|
1556
|
+
"rules": [
|
|
1557
|
+
{
|
|
1558
|
+
"name": "domain",
|
|
1559
|
+
"paths": ["src/domain/**"],
|
|
1560
|
+
"forbidden_imports": ["**/infrastructure/**"],
|
|
1561
|
+
}
|
|
1562
|
+
],
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
for suffix in ["java", "kt"]:
|
|
1566
|
+
for import_line in [
|
|
1567
|
+
"import com.example.infrastructure.SecretStore;",
|
|
1568
|
+
"import com.example.infrastructure.SecretStore; // boundary",
|
|
1569
|
+
"import com.example.infrastructure.SecretStore; /* boundary */",
|
|
1570
|
+
"import com.example.infrastructure.SecretStore; /* boundary",
|
|
1571
|
+
"import com.example.infrastructure.SecretStore; /* boundary */ // trailing",
|
|
1572
|
+
]:
|
|
1573
|
+
with self.subTest(suffix=suffix, import_line=import_line):
|
|
1574
|
+
path = f"src/domain/Order.{suffix}"
|
|
1575
|
+
issues = ap._structure_boundary_issues(
|
|
1576
|
+
path,
|
|
1577
|
+
[
|
|
1578
|
+
"package com.example.domain;",
|
|
1579
|
+
import_line,
|
|
1580
|
+
"",
|
|
1581
|
+
"class Order {}",
|
|
1582
|
+
],
|
|
1583
|
+
structure_cfg,
|
|
1584
|
+
)
|
|
1585
|
+
self.assertEqual(1, len(issues))
|
|
1586
|
+
self.assertIn("layer 'domain'", issues[0])
|
|
1587
|
+
self.assertIn("com.example.infrastructure.SecretStore", issues[0])
|
|
1588
|
+
|
|
1589
|
+
def test_function_ranges_follow_language_syntax(self) -> None:
|
|
1590
|
+
fixtures = [
|
|
1591
|
+
(
|
|
1592
|
+
"repository.go",
|
|
1593
|
+
[
|
|
1594
|
+
"package sample",
|
|
1595
|
+
"",
|
|
1596
|
+
"func (r *Repository) Find() error {",
|
|
1597
|
+
" if r == nil {",
|
|
1598
|
+
" return nil",
|
|
1599
|
+
" }",
|
|
1600
|
+
" return nil",
|
|
1601
|
+
"}",
|
|
1602
|
+
"",
|
|
1603
|
+
"var after = 1",
|
|
1604
|
+
],
|
|
1605
|
+
3,
|
|
1606
|
+
6,
|
|
1607
|
+
),
|
|
1608
|
+
(
|
|
1609
|
+
"normalize.py",
|
|
1610
|
+
[
|
|
1611
|
+
"def normalize(value):",
|
|
1612
|
+
" if value:",
|
|
1613
|
+
" return value",
|
|
1614
|
+
" return None",
|
|
1615
|
+
"after = 1",
|
|
1616
|
+
],
|
|
1617
|
+
1,
|
|
1618
|
+
4,
|
|
1619
|
+
),
|
|
1620
|
+
(
|
|
1621
|
+
"block-arrow.ts",
|
|
1622
|
+
[
|
|
1623
|
+
"const block = () => {",
|
|
1624
|
+
' const literal = "}";',
|
|
1625
|
+
" // } inside a comment is not the function end",
|
|
1626
|
+
" if (literal) {",
|
|
1627
|
+
" return literal;",
|
|
1628
|
+
" }",
|
|
1629
|
+
' return "";',
|
|
1630
|
+
"};",
|
|
1631
|
+
"const after = 1;",
|
|
1632
|
+
],
|
|
1633
|
+
1,
|
|
1634
|
+
8,
|
|
1635
|
+
),
|
|
1636
|
+
(
|
|
1637
|
+
"expression-arrow.ts",
|
|
1638
|
+
[
|
|
1639
|
+
"const expression = value =>",
|
|
1640
|
+
" value",
|
|
1641
|
+
" .trim()",
|
|
1642
|
+
" .toLowerCase();",
|
|
1643
|
+
"const after = 1;",
|
|
1644
|
+
],
|
|
1645
|
+
1,
|
|
1646
|
+
4,
|
|
1647
|
+
),
|
|
1648
|
+
(
|
|
1649
|
+
"parenthesized-arrow.ts",
|
|
1650
|
+
[
|
|
1651
|
+
"const expression = value => (",
|
|
1652
|
+
" value",
|
|
1653
|
+
" .trim()",
|
|
1654
|
+
" .toLowerCase()",
|
|
1655
|
+
");",
|
|
1656
|
+
"const after = 1;",
|
|
1657
|
+
],
|
|
1658
|
+
1,
|
|
1659
|
+
5,
|
|
1660
|
+
),
|
|
1661
|
+
(
|
|
1662
|
+
"conditional-arrow.ts",
|
|
1663
|
+
[
|
|
1664
|
+
"const choose = value => value ?",
|
|
1665
|
+
" first :",
|
|
1666
|
+
" second;",
|
|
1667
|
+
"const after = 1;",
|
|
1668
|
+
],
|
|
1669
|
+
1,
|
|
1670
|
+
3,
|
|
1671
|
+
),
|
|
1672
|
+
(
|
|
1673
|
+
"view-arrow.tsx",
|
|
1674
|
+
[
|
|
1675
|
+
"const View = () => <section>",
|
|
1676
|
+
" <span>value</span>",
|
|
1677
|
+
"</section>;",
|
|
1678
|
+
"const after = 1;",
|
|
1679
|
+
],
|
|
1680
|
+
1,
|
|
1681
|
+
3,
|
|
1682
|
+
),
|
|
1683
|
+
(
|
|
1684
|
+
"multiline-params.ts",
|
|
1685
|
+
[
|
|
1686
|
+
"const multi = (",
|
|
1687
|
+
" value: string,",
|
|
1688
|
+
" count: number,",
|
|
1689
|
+
") => {",
|
|
1690
|
+
" return value.repeat(count);",
|
|
1691
|
+
"};",
|
|
1692
|
+
"const after = 1;",
|
|
1693
|
+
],
|
|
1694
|
+
1,
|
|
1695
|
+
6,
|
|
1696
|
+
),
|
|
1697
|
+
(
|
|
1698
|
+
"typed-arrow-factory.ts",
|
|
1699
|
+
[
|
|
1700
|
+
"const factory = (): (x: string) => { value: string } => {",
|
|
1701
|
+
" const build = (value: string) => ({ value });",
|
|
1702
|
+
" return build;",
|
|
1703
|
+
"};",
|
|
1704
|
+
"const after = 1;",
|
|
1705
|
+
],
|
|
1706
|
+
1,
|
|
1707
|
+
4,
|
|
1708
|
+
),
|
|
1709
|
+
(
|
|
1710
|
+
"typed-generic-arrow-factory.ts",
|
|
1711
|
+
[
|
|
1712
|
+
"const factory = (): <T>(x: T) => { value: T } => {",
|
|
1713
|
+
" const build = <T>(value: T) => ({ value });",
|
|
1714
|
+
" return build;",
|
|
1715
|
+
"};",
|
|
1716
|
+
"const after = 1;",
|
|
1717
|
+
],
|
|
1718
|
+
1,
|
|
1719
|
+
4,
|
|
1720
|
+
),
|
|
1721
|
+
(
|
|
1722
|
+
"typed-constrained-generic-arrow.ts",
|
|
1723
|
+
[
|
|
1724
|
+
"const factory = <T extends (x: string) => { value: string }>(cb: T): void => {",
|
|
1725
|
+
" void cb;",
|
|
1726
|
+
" return;",
|
|
1727
|
+
"};",
|
|
1728
|
+
"const after = 1;",
|
|
1729
|
+
],
|
|
1730
|
+
1,
|
|
1731
|
+
4,
|
|
1732
|
+
),
|
|
1733
|
+
(
|
|
1734
|
+
"typed-defaulted-generic-arrow.ts",
|
|
1735
|
+
[
|
|
1736
|
+
"const factory = <T = () => { value: string }>(cb?: T): void => {",
|
|
1737
|
+
" void cb;",
|
|
1738
|
+
" return;",
|
|
1739
|
+
"};",
|
|
1740
|
+
"const after = 1;",
|
|
1741
|
+
],
|
|
1742
|
+
1,
|
|
1743
|
+
4,
|
|
1744
|
+
),
|
|
1745
|
+
(
|
|
1746
|
+
"typed-function.ts",
|
|
1747
|
+
[
|
|
1748
|
+
"export async function listBudgetRanges(",
|
|
1749
|
+
" scope: string,",
|
|
1750
|
+
"): Promise<BudgetRange[]> {",
|
|
1751
|
+
" return request(scope);",
|
|
1752
|
+
"}",
|
|
1753
|
+
"const after = 1;",
|
|
1754
|
+
],
|
|
1755
|
+
1,
|
|
1756
|
+
5,
|
|
1757
|
+
),
|
|
1758
|
+
(
|
|
1759
|
+
"typed-literal-function.ts",
|
|
1760
|
+
[
|
|
1761
|
+
"export function buildValue(): {",
|
|
1762
|
+
" value: string;",
|
|
1763
|
+
"} {",
|
|
1764
|
+
" return { value: 'ready' };",
|
|
1765
|
+
"}",
|
|
1766
|
+
"const after = 1;",
|
|
1767
|
+
],
|
|
1768
|
+
1,
|
|
1769
|
+
5,
|
|
1770
|
+
),
|
|
1771
|
+
(
|
|
1772
|
+
"typed-generic-constraint.ts",
|
|
1773
|
+
[
|
|
1774
|
+
"export function constrained<T extends { kind: string }>(",
|
|
1775
|
+
" value: T,",
|
|
1776
|
+
"): T {",
|
|
1777
|
+
" return value;",
|
|
1778
|
+
"}",
|
|
1779
|
+
"const after = 1;",
|
|
1780
|
+
],
|
|
1781
|
+
1,
|
|
1782
|
+
5,
|
|
1783
|
+
),
|
|
1784
|
+
(
|
|
1785
|
+
"typed-function-return.ts",
|
|
1786
|
+
[
|
|
1787
|
+
"export function makeFactory(): (x: string) => { value: string } {",
|
|
1788
|
+
" return value => ({ value });",
|
|
1789
|
+
"}",
|
|
1790
|
+
"const after = 1;",
|
|
1791
|
+
],
|
|
1792
|
+
1,
|
|
1793
|
+
3,
|
|
1794
|
+
),
|
|
1795
|
+
(
|
|
1796
|
+
"typed-generic-function-return.ts",
|
|
1797
|
+
[
|
|
1798
|
+
"export function makeGenericFactory(): <T>(x: T) => { value: T } {",
|
|
1799
|
+
" return value => ({ value });",
|
|
1800
|
+
"}",
|
|
1801
|
+
"const after = 1;",
|
|
1802
|
+
],
|
|
1803
|
+
1,
|
|
1804
|
+
3,
|
|
1805
|
+
),
|
|
1806
|
+
(
|
|
1807
|
+
"typed-conditional-return.ts",
|
|
1808
|
+
[
|
|
1809
|
+
"export function choose<T>(",
|
|
1810
|
+
" value: T,",
|
|
1811
|
+
"): T extends { kind: string } ? { matched: T } : { matched: never } {",
|
|
1812
|
+
" return { matched: value } as never;",
|
|
1813
|
+
"}",
|
|
1814
|
+
"const after = 1;",
|
|
1815
|
+
],
|
|
1816
|
+
1,
|
|
1817
|
+
5,
|
|
1818
|
+
),
|
|
1819
|
+
(
|
|
1820
|
+
"typed-keyof-return.ts",
|
|
1821
|
+
[
|
|
1822
|
+
"export function key(): keyof { ready: boolean } {",
|
|
1823
|
+
" return 'ready';",
|
|
1824
|
+
"}",
|
|
1825
|
+
"const after = 1;",
|
|
1826
|
+
],
|
|
1827
|
+
1,
|
|
1828
|
+
3,
|
|
1829
|
+
),
|
|
1830
|
+
(
|
|
1831
|
+
"typed-predicate-return.ts",
|
|
1832
|
+
[
|
|
1833
|
+
"export function isReady(value: unknown): value is { ready: true } {",
|
|
1834
|
+
" return Boolean(value);",
|
|
1835
|
+
"}",
|
|
1836
|
+
"const after = 1;",
|
|
1837
|
+
],
|
|
1838
|
+
1,
|
|
1839
|
+
3,
|
|
1840
|
+
),
|
|
1841
|
+
(
|
|
1842
|
+
"typed-multiline-generic-return.ts",
|
|
1843
|
+
[
|
|
1844
|
+
"export function load(): Promise<",
|
|
1845
|
+
" { value: string }",
|
|
1846
|
+
"> {",
|
|
1847
|
+
" return Promise.resolve({ value: 'ready' });",
|
|
1848
|
+
"}",
|
|
1849
|
+
"const after = 1;",
|
|
1850
|
+
],
|
|
1851
|
+
1,
|
|
1852
|
+
5,
|
|
1853
|
+
),
|
|
1854
|
+
(
|
|
1855
|
+
"typed-multiline-union-return.ts",
|
|
1856
|
+
[
|
|
1857
|
+
"export function union():",
|
|
1858
|
+
" | { kind: 'a' }",
|
|
1859
|
+
" | { kind: 'b' }",
|
|
1860
|
+
"{",
|
|
1861
|
+
" return { kind: 'a' };",
|
|
1862
|
+
"}",
|
|
1863
|
+
"const after = 1;",
|
|
1864
|
+
],
|
|
1865
|
+
1,
|
|
1866
|
+
6,
|
|
1867
|
+
),
|
|
1868
|
+
(
|
|
1869
|
+
"typed-commented-return.ts",
|
|
1870
|
+
[
|
|
1871
|
+
"export function commented(): /* result */ { value: string } {",
|
|
1872
|
+
" return { value: 'ready' };",
|
|
1873
|
+
"}",
|
|
1874
|
+
"const after = 1;",
|
|
1875
|
+
],
|
|
1876
|
+
1,
|
|
1877
|
+
3,
|
|
1878
|
+
),
|
|
1879
|
+
(
|
|
1880
|
+
"same-indent-plus.ts",
|
|
1881
|
+
[
|
|
1882
|
+
"const sum = value => value",
|
|
1883
|
+
"+ increment",
|
|
1884
|
+
"+ extra;",
|
|
1885
|
+
"const after = 1;",
|
|
1886
|
+
],
|
|
1887
|
+
1,
|
|
1888
|
+
3,
|
|
1889
|
+
),
|
|
1890
|
+
(
|
|
1891
|
+
"same-indent-chain.ts",
|
|
1892
|
+
[
|
|
1893
|
+
"const normalized = value => value",
|
|
1894
|
+
".trim()",
|
|
1895
|
+
".toLowerCase();",
|
|
1896
|
+
"const after = 1;",
|
|
1897
|
+
],
|
|
1898
|
+
1,
|
|
1899
|
+
3,
|
|
1900
|
+
),
|
|
1901
|
+
(
|
|
1902
|
+
"conditional-jsx.tsx",
|
|
1903
|
+
[
|
|
1904
|
+
"const Choice = value => (",
|
|
1905
|
+
" value ?",
|
|
1906
|
+
" <Accept /> :",
|
|
1907
|
+
" <Reject />",
|
|
1908
|
+
");",
|
|
1909
|
+
"const after = 1;",
|
|
1910
|
+
],
|
|
1911
|
+
1,
|
|
1912
|
+
5,
|
|
1913
|
+
),
|
|
1914
|
+
]
|
|
1915
|
+
trailing_top_level_lines = [f"top_level_{index} = {index}" for index in range(20)]
|
|
1916
|
+
for path, lines, start_line, expected_size in fixtures:
|
|
1917
|
+
with self.subTest(path=path):
|
|
1918
|
+
warnings = ap._function_size_warnings(
|
|
1919
|
+
path,
|
|
1920
|
+
lines + trailing_top_level_lines,
|
|
1921
|
+
expected_size - 1,
|
|
1922
|
+
)
|
|
1923
|
+
self.assertEqual(1, len(warnings))
|
|
1924
|
+
self.assertIn(f"{path}:{start_line}", warnings[0])
|
|
1925
|
+
self.assertIn(f"has {expected_size} lines", warnings[0])
|
|
1926
|
+
|
|
1927
|
+
def test_python_inline_suite_does_not_absorb_top_level_code(self) -> None:
|
|
1928
|
+
lines = ["def ready(): return True"] + [f"top_level_{index} = {index}" for index in range(200)]
|
|
1929
|
+
self.assertEqual([], ap._function_size_warnings("inline.py", lines, 120))
|
|
1930
|
+
|
|
1931
|
+
def test_multiline_arrow_declaration_has_one_size_finding(self) -> None:
|
|
1932
|
+
lines = [
|
|
1933
|
+
"const multi = (",
|
|
1934
|
+
" value: string,",
|
|
1935
|
+
") => {",
|
|
1936
|
+
*[f" const value_{index} = value;" for index in range(10)],
|
|
1937
|
+
"};",
|
|
1938
|
+
]
|
|
1939
|
+
warnings = ap._function_size_warnings("multi.ts", lines, 5)
|
|
1940
|
+
self.assertEqual(1, len(warnings), warnings)
|
|
1941
|
+
self.assertIn("multi.ts:1", warnings[0])
|
|
1942
|
+
|
|
1943
|
+
def test_same_line_fallback_uses_longest_callback(self) -> None:
|
|
1944
|
+
lines = [
|
|
1945
|
+
"consume(first => {}, second => {",
|
|
1946
|
+
*[f" const value_{index} = second;" for index in range(10)],
|
|
1947
|
+
"});",
|
|
1948
|
+
]
|
|
1949
|
+
warnings = ap._function_size_warnings("callbacks.ts", lines, 5)
|
|
1950
|
+
self.assertEqual(1, len(warnings), warnings)
|
|
1951
|
+
self.assertIn("callbacks.ts:1", warnings[0])
|
|
1952
|
+
|
|
1953
|
+
def test_function_ranges_ignore_type_braces_regex_literals_and_prior_assignments(self) -> None:
|
|
1954
|
+
long_body = [f" value_{index} := {index}" for index in range(130)]
|
|
1955
|
+
go_lines = [
|
|
1956
|
+
"package sample",
|
|
1957
|
+
"func build() struct {",
|
|
1958
|
+
" Value string",
|
|
1959
|
+
"} {",
|
|
1960
|
+
*long_body,
|
|
1961
|
+
" return struct { Value string }{}",
|
|
1962
|
+
"}",
|
|
1963
|
+
]
|
|
1964
|
+
self.assertEqual(1, len(ap._function_size_warnings("builder.go", go_lines, 120)))
|
|
1965
|
+
|
|
1966
|
+
js_lines = [
|
|
1967
|
+
"const block = () => {",
|
|
1968
|
+
" const matcher = /}/;",
|
|
1969
|
+
*[f" const value_{index} = {index};" for index in range(130)],
|
|
1970
|
+
"};",
|
|
1971
|
+
]
|
|
1972
|
+
self.assertEqual(1, len(ap._function_size_warnings("regex.js", js_lines, 120)))
|
|
1973
|
+
|
|
1974
|
+
separate_declarations = [
|
|
1975
|
+
'const label = "ready"',
|
|
1976
|
+
"const block = () => {",
|
|
1977
|
+
" return label;",
|
|
1978
|
+
"};",
|
|
1979
|
+
]
|
|
1980
|
+
self.assertEqual([], ap._function_size_warnings("separate.ts", separate_declarations, 3))
|
|
1981
|
+
|
|
1982
|
+
def test_function_range_scan_is_bounded_and_gate_deadline_is_enforced(self) -> None:
|
|
1983
|
+
depth = 4000
|
|
1984
|
+
lines = [f"function nested_{index}() {{" for index in range(depth)]
|
|
1985
|
+
lines.extend("}" for _ in range(depth))
|
|
1986
|
+
started = time.perf_counter()
|
|
1987
|
+
warnings = ap._function_size_warnings("nested.js", lines, 10)
|
|
1988
|
+
elapsed = time.perf_counter() - started
|
|
1989
|
+
self.assertEqual(depth - 5, len(warnings))
|
|
1990
|
+
self.assertLess(elapsed, 3.0, f"function scan must stay threshold-bounded, got {elapsed:.3f}s")
|
|
1991
|
+
|
|
1992
|
+
cfg = base_config()
|
|
1993
|
+
cfg["structure"] = {
|
|
1994
|
+
"enabled": True,
|
|
1995
|
+
"enforcement": "blocking",
|
|
1996
|
+
"max_function_lines_warn": 10,
|
|
1997
|
+
"layer_rules": {"enabled": False},
|
|
1998
|
+
}
|
|
1999
|
+
cfg["optimization"] = {"require_baseline_for_global_review": False}
|
|
2000
|
+
repo, _ = self.make_repo("src/app.js", cfg)
|
|
2001
|
+
with self.assertRaisesRegex(APError, "timed out during structure check"):
|
|
2002
|
+
ap._run_structure_check_for_gate(
|
|
2003
|
+
repo,
|
|
2004
|
+
cfg,
|
|
2005
|
+
"changed",
|
|
2006
|
+
"",
|
|
2007
|
+
deadline=time.monotonic() - 1,
|
|
2008
|
+
command_timeout_s=30,
|
|
2009
|
+
)
|
|
2010
|
+
|
|
1399
2011
|
def test_structure_scan_excludes_non_authoritative_agent_history_and_metadata(self) -> None:
|
|
1400
2012
|
repo, _ = self.make_repo()
|
|
1401
2013
|
files = {
|