# tuk Project Audit Issues

Status: Open
Audit date: 2026-05-28

---

## Critical (Runtime Bugs)

### 1. M2.cls:341-356 — cacheVal used outside If block

**Severity:** 🔴 Critical  
**File:** `sheet/M2.cls`  
**Line:** 341-356

`cacheVal` is declared inside `If cache.Exists(code)` block but used in `Select Case` below regardless:

```vba
If cache.Exists(code) Then
    Dim cacheVal As Variant: cacheVal = cache(code)
    ...
End If

Select Case kenshu
    Case "2"
        ws.Range("L" & rowNum).Value = Trim(cacheVal(1))  ' bug if code not in cache
```

Fix: move `Dim cacheVal As Variant` before the `If cache.Exists(code)` check.

---

### 2. C1.cls:984-997 — undeclared variables in Validate

**Severity:** 🔴 Critical  
**File:** `sheet/C1.cls`  
**Line:** 984-997

Three variables used without `Dim` in the kukan duplicate-check loop:

```vba
For kukanIdx = LBound(KUKAN_CODE_COLS) To UBound(KUKAN_CODE_COLS)
    kukanCol = KUKAN_CODE_COLS(kukanIdx)       ' not declared
    kukanCode = Trim(Me.Cells(rowNum, kukanCol).Value)
    ...
    kukanLetter = Split(Me.Cells(1, kukanCol).Address, "$")(1)  ' not declared
```

Fix: add `Dim kukanCol As Long, kukanCode As String, kukanLetter As String` at the top of `Validate`.

---

## AGENTS.md Violations

### 3. CJK Comments in Code

**Severity:** 🟡 AGENTS.md violation  
**Files:** `module/Common_Shape.bas`, `sheet/C1.cls`

| File | Line | Content |
|------|------|---------|
| `Common_Shape.bas` | 4 | `通用排版引擎（仅调整位置）` |
| `Common_Shape.bas` | 22 | `第一个图标左边对齐B3左边` |
| `Common_Shape.bas` | 44 | `你的专属调用入口` |
| `C1.cls` | 675 | `vals(1) = D列, vals(3) = F列, vals(4) = G列` |

Fix: translate to English per AGENTS.md English-only comments rule.

---

### 4. Hardcoded File Path in Import_modules

**Severity:** 🟡 AGENTS.md violation  
**File:** `init_module/Import_modules.bas`  
**Line:** 8

```vba
Const PROJECT_PATH As String = "D:\Project\upds7\vba\"
```

Fix: use a config-based path or a constant defined in `Common_Constants.bas`.

---

### 5. Hardcoded Sheet Name in Z4.cls

**Severity:** 🟡 AGENTS.md violation  
**File:** `sheet/Z4.cls`  
**Line:** 14

```vba
Set ws = ThisWorkbook.Worksheets("Z4")
```

Fix: use `CACHE_Z4` constant instead of the string literal.

---

### 6. Hardcoded "M1" in Common_Shape

**Severity:** 🟡 AGENTS.md violation  
**File:** `module/Common_Shape.bas`  
**Line:** 47

```vba
sheetName:="M1"
```

Fix: pass as parameter or use constant.

---

## Code Quality

### 7. O1/O2/O3 Validate Stubs

**Severity:** 🟠 Quality  
**Files:** `sheet/O1.cls`, `sheet/O2.cls`, `sheet/O3.cls`

All three have `Validate` methods that are empty stubs — just `Exit Sub`. If validation runs on these sheets, all rows pass silently.

Fix: implement proper validation or confirm empty stubs are intentional.

---

### 8. On Error Resume Next — 7 instances

**Severity:** 🟠 Quality  
**Files:** `Common_Global_Cache.bas`, `Common_Functions.bas`, `Common_Shape.bas`, `Test_Cache.bas`, `Import_modules.bas`

These silently swallow errors (e.g., "subscript out of range" for missing worksheets):

| File | Line | Target |
|------|------|--------|
| `Common_Global_Cache.bas` | 91 | `ThisWorkbook.Worksheets("M1")` |
| `Common_Global_Cache.bas` | 155 | `ThisWorkbook.Worksheets("M2")` |
| `Common_Global_Cache.bas` | 232 | `ThisWorkbook.Worksheets("M1")` |
| `Common_Functions.bas` | 101 | `ThisWorkbook.Worksheets(sheetName)` |
| `Common_Shape.bas` | 14 | `ThisWorkbook.Worksheets(sheetName)` |
| `Test_Cache.bas` | 25 | `ThisWorkbook.Worksheets("Test_Cache")` |
| `Import_modules.bas` | 82, 126 | `VBProject.VBComponents` |

Fix: use `On Error GoTo ErrHandler` pattern with `Err.Raise` for missing objects, or explicitly check worksheet existence before access.

---

### 9. Fixed Cell Reference in C1 Validate

**Severity:** 🟠 Quality  
**File:** `sheet/C1.cls`  
**Line:** 1000

```vba
Dim linkCellValue As String: linkCellValue = Me.Cells(3, "H").Value
```

Fixed address `Cells(3, "H")` used as a config switch. No constant or comment explaining its purpose.

Fix: add a named constant or sheetConf entry for this cell.

---

## Resolved / Correct

- All modules have `Option Explicit` ✅
- All `Worksheet_Change` handlers disable `EnableEvents` and use `Finally:` pattern ✅
- All sheet classes have English module headers ✅
- T2 `FillZeroIfEmpty` uses `sheetConf("ZeroFillCols")` with letter strings ✅
- Z4 `LookupZ4RosenCache` uses F col for rosen, D col for station ✅
- `Common_Selector.BuildZ4StationToDropdown` iterates `stationFromDict.Keys` to exclude `stationFrom` ✅
- No `Select`/`Selection`/`ActiveCell` patterns in sheet classes ✅
- All `Validate` methods in Z-series and T-series have proper checkResult pattern ✅

---

## Summary

| Severity | Count |
|----------|-------|
| 🔴 Critical | 2 |
| 🟡 AGENTS.md violation | 4 |
| 🟠 Code quality | 3 |

Priority: Fix #1 → #2 → #3 → #4