Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/22161-s19-five-file-fix-lines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"@objectstack/lint": patch
---

fix(lint): seven more rule ids print a `fix:` line of one remedy sentence, and `os explain RULE_ID` carries what those lines used to explain

Clause-②: no

- **Shorter fix lines.** Each finding of these 7 rule ids now carries a `hint` (the CLI's `fix:` line, the runtime advisory's `hint`) of one remedy sentence of at most 200 characters on every variant the lint suite fires (lengths are the `hint` alone; the CLI prints it after `fix: `). The longest of each, before → after:
- flow reference syntax (`lint-flow-patterns.ts`): `flow-double-brace-interpolation` (1413 → 197) and `flow-bare-dollar-reference` (1234 → 198);
- `liveness-ledger-unreadable` (270 → 82), `capability-reference-unknown` (241 → 131), `page-section-count-not-multi-value` (228 → 167), `list-view-filters-in-views-mode` (219 → 135) and `page-field-unknown` (206 → 94).
- **The flow ids keep the judge's spelling, and only where it evaluates.** In a value slot the line names the spec value-slot judge's own CEL envelope for the reference, read out of the judge's remedy and never re-spelled: FROM `A value slot reads a CEL value envelope, … so a bare $ reference is stored as written. $source.id names $source, which is not one of the flow engine's own $ variables, … Write {source.id} as { dialect: 'cel', source: 'source.id' }. CEL refuses an absent variable or key … (the guarded form writes null).` (681) TO ``A value slot stores a bare `$` reference as written: write `{source.id}` as { dialect: 'cel', source: 'source.id' }.`` (116). Where an envelope at the string's place would not evaluate (a string inside an object or list literal, a legacy `assignments: [{ variable, value }]` shape, a `$User` path that never resolved), the line names no envelope and points at `os explain`. It never names the build's own refusal for a `{{ }}` string, whose spelling keeps the outer braces as literal text. In a text slot the line names the `{{ }}` hole for each reference the engine binds, and for any other `$` root says to compute the value into a variable with an `assignment` node and write `{{ v }}`. At a notify or http literal it says neither brace dialect resolves there: write the value itself.
- **Lists are no longer echoed.** `page-field-unknown` no longer appends the object's whole field list; it names the nearest declared field ("Did you mean") instead.
- **`os explain RULE_ID` carries the rest.** What the fix lines stopped saying is each id's `RULE_EXPLANATIONS` entry in `@objectstack/lint`: the `has()` guard for a value that may be absent, the run user's `current_user` null guard and the `sys_user` read for any other `$User` path, the whole-value literal and the canonical `assignments` map, what a filter operand's `null` does, which slots read `{{ }}`, and where a brace token in a literal is refused; that a capability another installed package declares needs no change; why page filter controls do nothing on an object list view (ADR-0047); that a missing liveness ledger is a platform packaging fault; which field types take `multiple: true`. Six ids gain an entry, so their `rule:` line now carries the `os explain` pointer: `flow-double-brace-interpolation`, `flow-bare-dollar-reference`, `liveness-ledger-unreadable`, `page-field-unknown`, `page-section-count-not-multi-value` and `list-view-filters-in-views-mode`. `capability-reference-unknown`'s entry gains one sentence.
- **At the runtime publish gate** (Studio, REST `PUT /api/v1/meta`, and the MCP and AI authors that write through that door), the two flow ids fire on a `flow` write as 2xx `advisories[].hint`, FROM → TO measured at the door: a value-slot `$source.id` 681 → 116, `$User.Id` 681 → 121, `$User.Email` 742 → 198, a nested literal 1231 → 198, a legacy assignment 1030 → 198; a text-slot `$User.Id` 767 → 144 and `$error.message` 114 → 83; a value-slot `{{ }}` 746 → 116, a notify literal 297 → 137, a value no slot reads 362 → 158. Studio's save-advisory toast prints an advisory's `hint` after its message. `capability-reference-unknown` and `list-view-filters-in-views-mode` run at the CLI only; the two page ids do not fire on a `page` write; `liveness-ledger-unreadable` fires only on an install whose `@objectstack/spec` lost a ledger file.
- **Unchanged:** every `message` (the verdict), rule id, severity and `path`, and what each rule accepts or refuses.
228 changes: 198 additions & 30 deletions packages/lint/src/lint-flow-patterns.test.ts

Large diffs are not rendered by default.

137 changes: 98 additions & 39 deletions packages/lint/src/lint-flow-patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,16 +730,25 @@ function engineBindsRootOf(ref: string): boolean {
*/
function textSlotBareDollarHint(outsideHoles: string): string {
const holes: string[] = [];
const refusals: string[] = [];
const unbound: string[] = [];
for (const ref of bareDollarRefsOf(outsideHoles)) {
const refusal = textSlotTemplateRefusal(`{{ ${ref} }}`);
if (refusal === undefined) holes.push(`\`{{ ${ref} }}\``);
else refusals.push(`\`${ref}\` has no hole either: ${refusal}`);
if (textSlotTemplateRefusal(`{{ ${ref} }}`) === undefined) holes.push(`\`{{ ${ref} }}\``);
else unbound.push(`\`${ref}\``);
}
const parts = ['A text slot renders only `{{ }}` holes, and all other text is literal.'];
// [#22161] One remedy line: the hole for each reference the judge admits,
// and for the rest the remedy every refusal of an unbound `$` root ends
// with. The judge's per-root remedy (the run user's `current_user.id`, the
// flow's own variable written without the `$`, the user record a
// `get_record` reads) is `os explain flow-bare-dollar-reference`.
const parts = ['A text slot renders only `{{ }}` holes.'];
if (holes.length > 0) parts.push(`Write it as a hole: ${holes.join(', ')}.`);
parts.push(...refusals);
return parts.join(' ');
if (unbound.length > 0) {
parts.push(
`${unbound.join(', ')} ${unbound.length === 1 ? 'has' : 'have'} no hole: compute the value into a variable ` +
'with an `assignment` node and write `{{ v }}`.',
);
}
return withinHintBudget(parts.join(' '), TEXT_SLOT_FALLBACK);
}

/**
Expand Down Expand Up @@ -770,6 +779,59 @@ function valueSlotSpellingAt(at: ValueSlotPosition, text: string): string {
: message;
}

/** [#22161] The bound every `fix:` line of the two wrong-syntax rules holds to. */
const HINT_BUDGET = 200;

/** `hint` when it is one line within {@link HINT_BUDGET}, otherwise `fallback`. */
function withinHintBudget(hint: string, fallback: string): string {
return hint.length <= HINT_BUDGET ? hint : fallback;
}

/** A CEL value envelope as the spec's value-slot judge writes one in a remedy. */
const CEL_ENVELOPE = String.raw`\{ dialect: 'cel', source: (?:'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*") \}`;

/**
* [#22161] The judge's remedy, when it opens by spelling the token directly:
* `Write `{x}` as ENVELOPE` (a variable path, the run user's id, a date macro,
* an expression, a filter operand, a collection), or `` `text` is text with
* holes: write it as one CEL concatenation, ENVELOPE``. Every other opening
* (a string inside an object or list literal, a legacy `assignment` shape, a
* `$User` path that never resolved) means an envelope at the string's place
* would not evaluate, so no one-line spelling is taken from it.
*/
const DIRECT_SPELLING = new RegExp(
'^(?:Write (`[^`]+`) as|(`[^`]+`) is text with holes: write it as one CEL concatenation,) (' + CEL_ENVELOPE + ')',
);

/**
* [#22161] `TOKEN as ENVELOPE`, the judge's own spelling of `text` at `at`
* when its remedy opens with one ({@link DIRECT_SPELLING}), or `undefined`.
* Read out of the judge's words, never re-spelled here.
*/
function directSpellingAt(at: ValueSlotPosition, text: string): string | undefined {
const m = DIRECT_SPELLING.exec(valueSlotSpellingAt(at, text));
return m ? `${m[1] ?? m[2]} as ${m[3]}` : undefined;
}

/** [#22161] A value slot's bare-`$` `fix:` line where no direct spelling fits in one line. */
const VALUE_SLOT_BARE_DOLLAR_FALLBACK =
"A value slot stores a bare `$` reference as written: compute it in a CEL value envelope, `{ dialect: 'cel', "
+ "source: '…' }`, spelled as `os explain flow-bare-dollar-reference` says for this position.";

/**
* [#22161] A value slot's double-brace `fix:` line where no direct spelling fits in one line. It points at
* `os explain`, never at the build's own refusal: that refusal reads the string's outer braces as literal
* text, so its spelling keeps them (`'{' + record.title + '}'`), not the hole the author meant.
*/
const VALUE_SLOT_DOUBLE_BRACE_FALLBACK =
"A value slot reads no `{{ }}` template: compute the value in a CEL value envelope, `{ dialect: 'cel', "
+ "source: '…' }`, spelled as `os explain flow-double-brace-interpolation` says for this position.";

/** [#22161] A text slot's bare-`$` `fix:` line where the references do not fit in one line. */
const TEXT_SLOT_FALLBACK =
'A text slot renders only `{{ }}` holes: write each reference as a hole over a variable the run binds '
+ '(`os explain flow-bare-dollar-reference`).';

/**
* [#19939] The hint for bare `$name.path` references in a VALUE slot's string.
* A value slot reads the CEL value envelope, so each reference is prescribed
Expand All @@ -788,22 +850,21 @@ function valueSlotSpellingAt(at: ValueSlotPosition, text: string): string {
* written without the `$` (`$source.id` names `{source.id}`).
*/
function valueSlotBareDollarHint(text: string, at: ValueSlotPosition): string {
const parts = [
'A value slot reads a CEL value envelope, `{ dialect: \'cel\', source: \'…\' }`: a string in it is the literal '
+ 'text it spells, so a bare `$` reference is stored as written.',
];
const spellings: string[] = [];
for (const ref of bareDollarRefsOf(text)) {
const ownVariable = !isRunUserRef(ref) && !engineBindsRootOf(ref);
const root = ref.split('.')[0]!;
const token = ownVariable ? `{${ref.slice(1)}}` : `{${ref}}`;
parts.push(
ownVariable
? `\`${ref}\` names \`${root}\`, which is not one of the flow engine's own \`$\` variables, so it reads `
+ `as the flow's own variable, written without the \`$\`: ${valueSlotSpellingAt(at, token)}`
: `\`${ref}\` reads as \`${token}\`: ${valueSlotSpellingAt(at, token)}`,
);
const spelling = directSpellingAt(at, ownVariable ? `{${ref.slice(1)}}` : `{${ref}}`);
if (spelling === undefined) return VALUE_SLOT_BARE_DOLLAR_FALLBACK;
spellings.push(spelling);
}
return parts.join(' ');
// [#22161] One remedy line: the judge's own spelling of each reference.
// What else the judge says at the position (a guard for a value that may
// be absent, what a callee or the client is handed) is
// `os explain flow-bare-dollar-reference`.
return withinHintBudget(
`A value slot stores a bare \`$\` reference as written: write ${spellings.join('; ')}.`,
VALUE_SLOT_BARE_DOLLAR_FALLBACK,
);
}

/** Every `{{ path }}` hole in a string — what {@link valueSlotDoubleBraceHint} reads as the author's intent. */
Expand All @@ -820,13 +881,13 @@ const DOUBLE_BRACE_HOLES = /\{\{\s*([\w$][\w$.\s]*?)\s*\}\}/g;
*/
function valueSlotDoubleBraceHint(text: string, at: ValueSlotPosition): string {
const meant = text.replace(DOUBLE_BRACE_HOLES, (_hole, path: string) => `{${path}}`);
return (
'A value slot reads a CEL value envelope, `{ dialect: \'cel\', source: \'…\' }`, and no template: a string in it '
+ 'is the literal text it spells, and `{{ }}` is no hole — the value-slot refusal reads its outer braces as '
+ `literal text. Written as the holes it means: ${valueSlotSpellingAt(at, meant)} Double-brace \`{{ }}\` is the `
+ 'template dialect of the text slots only — a notify `title` / `message` / `actionUrl`, an http `url` and '
+ '`headers` values, a screen `title` / `description`, an `end` `message`.'
);
const spelling = directSpellingAt(at, meant);
// [#22161] One remedy line: the judge's own spelling of the holes it means.
// That the value-slot refusal reads the outer braces as literal text, and
// which slots read `{{ }}`, is `os explain flow-double-brace-interpolation`.
return spelling === undefined
? VALUE_SLOT_DOUBLE_BRACE_FALLBACK
: withinHintBudget(`A value slot reads no \`{{ }}\` template: write ${spelling}.`, VALUE_SLOT_DOUBLE_BRACE_FALLBACK);
}

/** Config keys whose string values are CEL predicates, not interpolated templates. */
Expand Down Expand Up @@ -860,21 +921,23 @@ const LITERAL_KEYS: ReadonlyMap<string, ReadonlySet<string>> = new Map([
const ELSEWHERE_HINT =
'This flow node value is read as written: neither `{var}` nor `{{ }}` resolves here, and nothing evaluates a '
+ 'reference, braced or bare. Write the value itself.';
// [#22161] Which slots read `{{ }}` left the double-brace finding's line here;
// it is `os explain flow-double-brace-interpolation`.

/** The hint of either finding at a node's literal, by node type: nothing resolves a reference there. */
const LITERAL_HINTS: ReadonlyMap<string, string> = new Map([
// [#22161] One remedy line each; that a brace token in one is refused at
// `objectstack validate` and `registerFlow` (and in `signingSecret` by the
// executor's parse) is each rule's `os explain` entry.
[
'notify',
'A notify node\'s `sourceObject`, `actorId` and `payload` are literals the executor reads as written: neither '
+ '`{var}` nor `{{ }}` resolves there, and nothing evaluates a reference, braced or bare — a brace token in one '
+ 'is refused at `objectstack validate` and `registerFlow`. Write the value itself.',
'A notify node\'s `sourceObject`, `actorId` and `payload` are literals: neither `{var}` nor `{{ }}` resolves '
+ 'there. Write the value itself.',
],
[
'http',
'An http node\'s `method`, `durable`, `timeoutMs` and `signingSecret` are literals the executor reads as '
+ 'written: neither `{var}` nor `{{ }}` resolves there, and nothing evaluates a reference, braced or bare — a '
+ 'brace token in one is refused at `objectstack validate` and `registerFlow`, and in `signingSecret`, whose '
+ 'secret the flow credential store may hold, by the executor\'s parse. Write the value itself.',
'An http node\'s `method`, `durable`, `timeoutMs` and `signingSecret` are literals: neither `{var}` nor `{{ }}` '
+ 'resolves there. Write the value itself.',
],
]);

Expand Down Expand Up @@ -2040,11 +2103,7 @@ export function lintFlowPatterns(stack: AnyRec): FlowLintFinding[] {
message: valueSlot === undefined
? `double-brace interpolation \`${str.trim().slice(0, 80)}\` — nothing renders a template here: this flow node value is read as written.`
: `double-brace interpolation \`${str.trim().slice(0, 80)}\` — the ${valueSlot} reads a CEL value envelope, not a template.`,
hint: valueSlot === undefined
? `${ELSEWHERE_HINT} Double-brace \`{{ }}\` is ` +
`the template dialect of the text slots only — a notify \`title\` / \`message\` / \`actionUrl\`, an http \`url\` and \`headers\` values, a screen ` +
`\`title\` / \`description\`, an \`end\` \`message\`.`
: valueSlotDoubleBraceHint(str, at),
hint: valueSlot === undefined ? ELSEWHERE_HINT : valueSlotDoubleBraceHint(str, at),
rule: FLOW_DOUBLE_BRACE_INTERP,
});
}
Expand Down
22 changes: 22 additions & 0 deletions packages/lint/src/lint-liveness-properties.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
lintLivenessPropertiesFromLedgerDir,
resolveLivenessDir,
} from './lint-liveness-properties.js';
import { explainRule } from './rule-explanations.js';

/**
* These run against the REAL ledgers shipped by `@objectstack/spec` (the same
Expand Down Expand Up @@ -2109,3 +2110,24 @@ describe('#23710 — a page declaring `print` lints without a planned-property w
expect(findings.filter((f) => f.rule === LIVENESS_LEDGER_UNREADABLE)).toEqual([]);
});
});

// [#22161] Slice 19: the ledger-fault `fix:` line is one remedy line; that it
// is a packaging fault and what the rule's silence means is the explanation's.
describe('[#22161] one-line fix — liveness-ledger-unreadable', () => {
it('a missing and an unreadable ledger both print the one remedy line, and `os explain` carries the rest', () => {
const missing = lintLivenessPropertiesFromLedgerDir(ledgerDirWith((dir) => rmSync(join(dir, 'object.json'))), {});
const unreadable = lintLivenessPropertiesFromLedgerDir(
ledgerDirWith((dir) => writeFileSync(join(dir, 'object.json'), '{ not json')),
{},
);
const hints = [...missing, ...unreadable].filter((f) => f.rule === LIVENESS_LEDGER_UNREADABLE).map((f) => f.hint);
expect(hints).toEqual([
'Reinstall or repair `@objectstack/spec` so its `liveness/` directory ships intact.',
'Reinstall or repair `@objectstack/spec` so its `liveness/` directory ships intact.',
]);
const text = explainRule(LIVENESS_LEDGER_UNREADABLE)!.paragraphs.join('\n');
for (const fact of ['packaging fault in the platform, not an authoring error', 'silence about that type means nothing', 'once per run']) {
expect(text, fact).toContain(fact);
}
});
});
8 changes: 4 additions & 4 deletions packages/lint/src/lint-liveness-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,10 +655,10 @@ function ledgerFaultFindings(faults: ReadonlyMap<string, LedgerFault>): Liveness
message:
`every author warning for \`${type}\` metadata is switched off: ${LEDGER_FAULT_CAUSE[fault]} ` +
`(expected \`${type}.json\` beside the other liveness ledgers \`@objectstack/spec\` ships).`,
hint:
'This is a packaging fault in the platform, not an authoring error: nothing in the metadata ' +
'being linted caused it, and this rule’s silence about this type means nothing until it is ' +
'fixed. Reinstall or repair `@objectstack/spec` so its `liveness/` directory ships intact.',
// [#22161] One remedy line; that this is a platform packaging fault and
// what the rule's silence means until it is fixed is
// `os explain liveness-ledger-unreadable`.
hint: 'Reinstall or repair `@objectstack/spec` so its `liveness/` directory ships intact.',
rule: LIVENESS_LEDGER_UNREADABLE,
}));
}
Expand Down
Loading
Loading