Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

tech(M2): `git -C /repo commit --no-verify` faellt jetzt auch

David99d9be0e21c7
diff --git a/src/lib/__tests__/shell-command-classify.test.ts b/src/lib/__tests__/shell-command-classify.test.ts
index 0c50f320..10245c34 100644
--- a/src/lib/__tests__/shell-command-classify.test.ts
+++ b/src/lib/__tests__/shell-command-classify.test.ts
@@ -229,6 +229,74 @@ describe('the --no-verify ban applies to a commit anywhere in the line', () => {
})
})
+// Ein Segment gilt als Commit, wenn es mit `git` beginnt UND `commit` als Wort
+// enthaelt — nicht `^git\s+commit`. Gits eigene Globaloptionen stehen sonst
+// dazwischen und die Sperre laeuft ins Leere. Die Regel weiss nichts von `-C`,
+// `-c` oder `--git-dir`, weil sie gar nicht erst versucht, sie zu ueberspringen.
+describe('the ban survives git\'s own global options in front of `commit`', () => {
+ const refused = (c: string) => rejectShellCommand(c) !== null
+
+ it('refuses a commit behind -C', () => {
+ expect(refused('git -C /repo commit --no-verify -m x')).toBe(true)
+ })
+
+ it('refuses a commit behind -c', () => {
+ expect(refused('git -c a=b commit --no-verify -m x')).toBe(true)
+ })
+
+ it('refuses a commit behind --git-dir', () => {
+ expect(refused('git --git-dir=/r/.git commit --no-verify -m x')).toBe(true)
+ })
+
+ it('refuses those forms behind a chain as well', () => {
+ expect(refused('cd repo; git -C /repo commit --no-verify -m x')).toBe(true)
+ expect(refused('echo hi && git -c a=b commit --no-verify -m x')).toBe(true)
+ })
+
+ // Negativkontrollen: die Weitung darf keine der Zeilen fangen, die vorher
+ // durchliefen. Alle drei tragen kein --no-verify, also entscheidet allein
+ // der Commit-Matcher — und der darf hier nichts ausloesen.
+ it('leaves the ordinary lines alone', () => {
+ expect(rejectShellCommand('git log --grep=commit')).toBeNull()
+ expect(rejectShellCommand('git status && ls')).toBeNull()
+ expect(rejectShellCommand('git add -A && git commit -m wip')).toBeNull()
+ })
+
+ // Ein git-Kommando mit ECHTEM --no-verify, das kein Commit ist, bleibt frei:
+ // die Sperre gilt dem Commit-Hook, nicht dem Flag an sich.
+ it('does not touch a non-commit git command that legitimately carries the flag', () => {
+ expect(rejectShellCommand('git push --no-verify')).toBeNull()
+ expect(rejectShellCommand('git merge --no-verify feature')).toBeNull()
+ })
+})
+
+// Die Kehrseite der Ganzzeilen-Pruefung, ausdruecklich festgehalten statt als
+// unbeschriebene Nebenwirkung stehenzulassen. `--no-verify` wird gegen die
+// GANZE Zeile geprueft, weil der Split anfuehrungszeichen-blind ist; damit
+// faellt jede Zeile mit, die irgendwo das Flag traegt UND irgendwo ein
+// Commit-Segment hat. Das ist die gewollte Richtung — lieber eine Zeile zu
+// viel ablehnen als eine Umgehung offen lassen.
+describe('accepted false alarms of the whole-line flag test', () => {
+ const refused = (c: string) => rejectShellCommand(c) !== null
+
+ it('refuses a commit whose line merely MENTIONS the flag elsewhere', () => {
+ // Der Commit selbst ist gewoehnlich; das Flag steht im echo. Ablehnen ist
+ // richtig: unterscheiden koennte man die beiden nur per Segment, und die
+ // Segmentpruefung ist genau die Umgehung (`git commit -m "a;b"
+ // --no-verify`), die oben geschlossen wurde.
+ expect(refused('echo --no-verify && git commit -m x')).toBe(true)
+ })
+
+ it('refuses an ordinary commit chained with a push that skips the PUSH hook', () => {
+ // Bekannter Fehlalarm, im Bericht als offene Frage vermerkt: hier gehoert
+ // --no-verify zu `git push`, nicht zum Commit, und der Nutzer bekommt eine
+ // Meldung ueber `git commit --no-verify`, die nicht zu seiner Zeile passt.
+ // Faellt weg, sobald die Sperre segmentlokal entscheidet — dann kippt diese
+ // Erwartung bewusst, statt still.
+ expect(refused('git add -A && git commit -m wip && git push --no-verify')).toBe(true)
+ })
+})
+
describe('timeout and icon follow the command', () => {
it('a recognised test run keeps the 300 s budget', () => {
expect(commandTimeoutMs('npm test', 600_000)).toBe(TEST_RUN_TIMEOUT_MS)
diff --git a/src/lib/shell-command-classify.ts b/src/lib/shell-command-classify.ts
index 608116d1..34302209 100644
--- a/src/lib/shell-command-classify.ts
+++ b/src/lib/shell-command-classify.ts
@@ -167,10 +167,25 @@ function commandSegments(command: string): string[] {
* (`git commit -m "a;b" --no-verify`) and hand back the very bypass this is
* closing. Testing the wider string can only ever refuse more, never less.
*
+ * A segment counts as a commit when it STARTS with `git` and mentions
+ * `commit` as a word — not `^git\s+commit`, which git's own global options
+ * walk straight past (`git -C /repo commit`, `git -c a=b commit`,
+ * `git --git-dir=… commit`). Skipping those options properly would mean
+ * parsing git's option grammar AND shell quoting (`git -c 'a b' commit`
+ * defeats any token walk), and an option-skipper that is wrong in the
+ * permissive direction is a new bypass rather than a fix. This test needs to
+ * know none of it: it is deliberately too coarse, in the same direction as
+ * the whole-line flag test. What it costs is a segment that merely SAYS
+ * commit while the line also carries the flag — `git log --grep=commit
+ * --no-verify`, which is not a thing anybody writes, since `--no-verify` is
+ * no `log` flag.
+ *
* Returns the refusal text, or null when the command may run.
*/
export function rejectShellCommand(command: string): string | null {
- const commits = commandSegments(command).some((seg) => /^git\s+commit\b/.test(seg))
+ const commits = commandSegments(command).some(
+ (seg) => /^git\b/.test(seg) && /\bcommit\b/.test(seg),
+ )
if (commits && /--no-verify\b/.test(command)) {
return 'Refused: git commit --no-verify skips the repository hooks. Fix what the hook reports instead of silencing it, then commit normally.'
}
diff --git a/src/stores/__tests__/remoteStore-v2.test.ts b/src/stores/__tests__/remoteStore-v2.test.ts
index 135418de..d483f28b 100644
--- a/src/stores/__tests__/remoteStore-v2.test.ts
+++ b/src/stores/__tests__/remoteStore-v2.test.ts
@@ -21,6 +21,9 @@ import { backendCall } from '../../api/backend'
import { prop } from '../../types/json-guards'
const mockBackend = backendCall as unknown as ReturnType<typeof vi.fn>
+/** Die unveraenderte Implementierung, einmal vor dem ersten Test gegriffen. */
+const realGetMemoriesForPrompt = useMemoryStore.getState().getMemoriesForPrompt
+
beforeEach(() => {
mockBackend.mockClear()
useRemoteStore.setState({
@@ -41,10 +44,13 @@ beforeEach(() => {
dispatchedConversationId: null,
qrVisible: false,
})
- // NOTE: this reset named `memories`, a field the memory store does not
- // have — `as any` let it compile, so it never reset anything. The real
- // field is `entries`.
- useMemoryStore.setState({ entries: [] })
+ // Der Reset hiess frueher `memories` — ein Feld, das der Store nicht hat;
+ // `as any` liess es kompilieren, also hat er nie etwas zurueckgesetzt. Neben
+ // dem richtigen Feldnamen gehoert die ECHTE `getMemoriesForPrompt` wieder
+ // hin: mehrere Tests unten ersetzen sie, und ohne diese Zeile trug jede
+ // Ersetzung in alle folgenden Tests weiter — die Testreihenfolge entschied
+ // dann mit, was ein Test sieht.
+ useMemoryStore.setState({ entries: [], getMemoriesForPrompt: realGetMemoriesForPrompt })
})
afterEach(() => {
@@ -243,6 +249,20 @@ describe('remoteStore › memory enrichment behaviour', () => {
})
})
+// Laeuft NACH dem Block, der `getMemoriesForPrompt` mehrfach ersetzt. Wenn das
+// beforeEach die echte Implementierung nicht zuruecklegt, sieht dieser Test die
+// letzte Attrappe des vorigen Blocks statt des Stores — genau die stille
+// Reihenfolgen-Abhaengigkeit, die hier festgenagelt wird.
+describe('remoteStore › the memory store is isolated between tests', () => {
+ it('sees the real getMemoriesForPrompt again, not the previous block\'s stub', () => {
+ expect(useMemoryStore.getState().getMemoriesForPrompt('anything', 8192)).toBe('')
+ })
+
+ it('and an empty entries list', () => {
+ expect(useMemoryStore.getState().entries).toEqual([])
+ })
+})
+
describe('remoteStore › permissions state', () => {
it('can set filesystem permission', () => {
useRemoteStore.setState({