# UI Page Plugin Review Rules

> Auto-generated by pr-review-rules-generator skill on 2026-02-24
> Source: git history mining (DEF commits, reverts) + domain expertise interview

## Overview

Rules for the UI page plugin (`src/ui-page/`) and related glob/path utilities. This plugin
generates ServiceNow UI page output and has had multiple defects related to caching, HTML entity
handling, path separator normalization, and UX asset import patterns.

## Rules

---

## Rule ID: ui_page_cache_busting

**Summary:** Verify UI page output includes proper cache-busting for ServiceNow instance delivery

**Rationale:** DEF0737951 revealed that UI pages served from ServiceNow instances were being
cached aggressively, causing stale JS to be served to end users after deployments. The fix went
through multiple iterations (hash-suffixed filenames → query params → `enableCacheBusting` option
with asset flush timestamp). The current mechanism uses a `uxpcb` query parameter. Any change to
how script URLs or entry file names are generated must preserve this cache-busting behavior, and
must handle the case where a `uxpcb` param already exists in the URL (to avoid duplicate params).

**Scope:**
- Paths: `src/ui-page/**`
- Change Types: `modify`

**Detection Guidance:** When reviewing changes to URL or filename generation in the UI page plugin,
check: (1) that the `enableCacheBusting` option is respected, (2) that a cache-busting param is
appended to script `src` URLs, (3) that if `uxpcb` is already present it is updated rather than
duplicated, and (4) that the timestamp/hash used is consistent within a single build invocation.
Search the diff for any changes to `generateBundle`, `renderChunk`, or where HTML `<script src>`
attributes are constructed.

**Severity:** `error`

**Source:**
- Type: `incident`
- Refs: DEF0737951, 4f45f1a, 6565e00
- Confidence: high

**Override:**
- Allowed: true
- Requires: justification

**Examples:**

### Violation Example
```typescript
// ❌ Bad: script src has no cache-busting — will be served from instance cache indefinitely
`<script src="${entryFile}"></script>`
```

### Correct Example
```typescript
// ✅ Good: append cache-flush timestamp as query param
const src = enableCacheBusting
  ? appendQueryParam(entryFile, 'uxpcb', flushTimestamp)
  : entryFile;
`<script src="${src}"></script>`
```


---

## Rule ID: ui_page_no_entity_decoding

**Summary:** Do not apply HTML entity decoding to UI page parser output

**Rationale:** DEF0727941 identified that applying HTML entity decoding to the parsed UI page
content caused double-decoding issues — entities like `&amp;` would become `&` prematurely,
corrupting inline content. The parser should emit content as-is; entity handling is the
responsibility of the downstream consumer or the browser renderer.

**Scope:**
- Paths: `src/ui-page/**`

**Detection Guidance:** Look for any calls to entity-decoding utilities (e.g., `he.decode`,
`decodeHTMLEntities`, `unescape`, or similar) applied to HTML string content returned from the
parser. If an HTML parsing library is being used or upgraded, check whether it performs entity
decoding by default and whether that behavior is being disabled.

**Severity:** `error`

**Source:**
- Type: `incident`
- Refs: DEF0727941, fb70841
- Confidence: high

**Override:**
- Allowed: false
- Requires: n/a


---

## Rule ID: glob_path_normalization

**Summary:** All glob and path operations must normalize backslashes to forward slashes for Windows compatibility

**Rationale:** DEF0738554 found that glob patterns with Windows-style backslash separators
(`\`) were not matching files on Windows build environments. The fix normalized path separators
before passing them to the glob library. Because this is a build tool consumed in developer
environments (not just CI), and ServiceNow developers work on Windows, cross-platform path
handling is required in all path manipulation code.

**Scope:**
- Paths: `src/glob/**`, `src/ui-page/**`, `src/**/*.ts`, `src/**/*.js`

**Detection Guidance:** For any code that constructs or processes file paths before passing them
to glob patterns or file lookup functions, check that backslashes are replaced with forward
slashes. Look for string concatenation or `path.join` calls used directly in glob patterns —
these are the most common source of the issue. Verify that any new `path.join` calls in platform-
agnostic code are followed by a `.replace(/\\/g, '/')` normalization.

**Severity:** `error`

**Source:**
- Type: `incident`
- Refs: DEF0738554, 9e10be3
- Confidence: high

**Override:**
- Allowed: true
- Requires: justification

**Examples:**

### Violation Example
```typescript
// ❌ Bad: path.join uses OS-native separator — breaks glob on Windows
const pattern = path.join(rootDir, 'src/**/*.ts');
const files = glob.sync(pattern);
```

### Correct Example
```typescript
// ✅ Good: normalize to forward slashes before glob
const pattern = path.join(rootDir, 'src/**/*.ts').replace(/\\/g, '/');
const files = glob.sync(pattern);
```


---

## Rule ID: uxasset_import_assertions

**Summary:** UX asset imports must use `with` attribute assertions, not the legacy `uxasset-external:` prefix

**Rationale:** The repo migrated from a custom `uxasset-external:` import prefix scheme
(MAINT: `d57c43d`, `dfee06a`) to the standard `with` import attribute syntax
(MAINT: `1cf8d3c`). The legacy prefix approach is no longer supported. Any new code that handles
UX asset imports (images, fonts, CSS) must use the `with { type: 'uxasset' }` import assertion
pattern, not the old prefix. Using the old pattern will cause assets to be mis-bundled or ignored
on the instance.

**Scope:**
- Paths: `src/**`, `example/**`

**Detection Guidance:** Search the diff for string literals containing `uxasset-external:` — these
indicate use of the deprecated prefix. Also check that the plugin handling import assertions reads
the `with` attribute rather than matching on an ID prefix. If the PR adds a new file type or asset
handling path, verify it follows the `with` attribute pattern.

**Severity:** `warning`

**Source:**
- Type: mined
- Refs: 1cf8d3c, d57c43d, dfee06a
- Confidence: medium

**Override:**
- Allowed: true
- Requires: justification

**Examples:**

### Violation Example
```typescript
// ❌ Deprecated: prefix-based uxasset import
import logo from 'uxasset-external:./logo.png';
```

### Correct Example
```typescript
// ✅ Current: import assertion with 'with' attribute
import logo from './logo.png' with { type: 'uxasset' };
```


---

## Attribution

All rules are traceable to specific sources:
- `incident` = Direct from production defect (DEF*)
- `mined` = Derived from git history analysis
- `interview` = Captured during domain expertise interview

## Override Mechanism

To override a rule in a PR:

1. **In PR description:**
   ```markdown
   <!-- pr-review: skip ui_page_cache_busting reason="Justification here" -->
   ```

2. **In repo config (`.pr-review-config.yaml`):**
   ```yaml
   overrides:
     - rule_id: glob_path_normalization
       paths: ["path/to/exclude/**"]
       reason: "Why this path is exempt"
   ```

Note: Rules marked `override.allowed: false` cannot be skipped without approval.
