Artifact 0fa1fbf8e07b9ca90955f0ed3e99eb567660be042779d66c4addfcbc17d458f7:
- File
src/lint.h
— part of check-in
[6516a0e4da]
at
2026-11-13 12:54:25
on branch trunk
— Phase 7a: a lint guards every check-in, and edits made in place are checked in
suit lint and suit commit refuse a change that holds a token-shaped value, tool-attribution text, a symlink, or a skill folder with no header. A suit.lint file in the wardrobe can exempt a path or forbid an extra phrase. The lint never changes a file.
suit tend is the hourly entry point. For now it checks in edits made in the store, after the lint. A change that deletes more than five files and more than a fifth of the wardrobe is held until it is confirmed. Anything that needs a person is written to an attention file, which suit status shows under 'needs you'.
A symlink refusal now comes from the lint and exits 3, where it exited 16 before.
Also fixed, found by the forge's runner: a file suit rewrote came back with default permissions, keeping only its executable bit. On the runner a project's local exclude file went from rw-rw---- to rw-r----- across apply and off. A rewritten file now keeps exactly the permissions it had. Tests rewrite files of four different modes under two different defaults, so the development machine catches it too. Three tests that restored a folder to a fixed mode now put back only the bits they took away.
1204 unit checks, 227 shell cases, 323 store cases, 612 placement cases and 378 project cases, under clang, under gcc 16, with no user name set, and under a strict umask. 100% coverage in all 21 source files. No suite has fewer cases than at the last check-in. (user: dmestas, size: 2455) [annotate] [blame] [check-ins using]
#ifndef SUIT_LINT_H #define SUIT_LINT_H #include <stddef.h> #include <stdint.h> // The lint: what a file in the store must not hold before it is checked in // (docs/store.md, "The lint"). It reads text and reports; it changes nothing. constexpr size_t LINT_FILE_MAX = 4194304; // a larger file is refused, not scanned constexpr size_t LINT_LINE_MAX = 65536; // a longer line is refused constexpr size_t LINT_BINARY_PROBE = 8192; // a NUL in this many bytes makes a file binary // suit.lint, at the wardrobe's top: `allow PATH` and `forbid TEXT` lines. constexpr char LINT_RULES_NAME[] = "suit.lint"; constexpr size_t LINT_RULES_FILE_MAX = 65536; constexpr size_t LINT_RULES_LINE_MAX = 1024; constexpr size_t LINT_TEXT_MAX = 200; // the longest forbidden text constexpr uint32_t LINT_ALLOW_MAX = 256; constexpr uint32_t LINT_FORBID_MAX = 64; typedef struct { uint32_t n_allow; uint32_t n_forbid; const char *allow[LINT_ALLOW_MAX]; const char *forbid[LINT_FORBID_MAX]; // lower case char buf[LINT_RULES_FILE_MAX + 1]; } LintRules; // line is 0 when the error concerns the whole file. err is the error number // of a file that could not be read, else 0. typedef struct { int line; int err; char msg[256]; } LintError; // Parse DATA (LEN bytes) as a suit.lint. On failure R is empty and ERR says // what and where. [[nodiscard]] bool lint_rules_parse(LintRules *r, const char *data, size_t len, LintError *err); // Read PATH. A file that is not there is no rules. [[nodiscard]] bool lint_rules_load(LintRules *r, const char *path, LintError *err); // Whether R exempts the file PATH (relative to the wardrobe's top) from the // token and attribution rules. bool lint_allowed(const LintRules *r, const char *path); // What is wrong with LINE (LEN bytes, no newline), as a fixed text, or nullptr. const char *lint_line(const LintRules *r, const char *line, size_t len); // Called for each problem: LINE is 1-based. typedef void (*LintSink)(void *state, size_t line, const char *what); // Scan one file's bytes: nothing if they look binary, else every line through // lint_line (unless EXEMPT) and a refusal for a line over LINT_LINE_MAX. // Returns the number of problems. size_t lint_text(const LintRules *r, bool exempt, const char *data, size_t len, LintSink sink, void *state); // Whether a SKILL.md begins with a "---" line. bool lint_has_header(const char *data, size_t len); #endif