MCPcopy
hub / github.com/vercel-labs/agent-skills / verifyPatternCount

Function verifyPatternCount

skills/vercel-optimize/lib/verify-claim.mjs:90–108  ·  view source on GitHub ↗
(claim)

Source from the content-addressed store, hash-verified

88}
89
90async function verifyPatternCount(claim) {
91 const { file, pattern, expected } = claim;
92 if (!file || !pattern) return { disposition: 'unsupported', reason: 'pattern_count requires file + pattern' };
93 let content;
94 try { ({ content } = await readClaimFile(claim)); }
95 catch { return { disposition: 'failed', reason: `cannot read ${file}` }; }
96
97 // "42" alone (from `filename:42`) is a line number, not a pattern.
98 if (/^\d+$/.test(pattern.trim())) {
99 return { disposition: 'unsupported', reason: 'pattern looks like a line number, not a pattern' };
100 }
101
102 const re = compilePattern(pattern, 'g');
103 const matches = content.match(re) ?? [];
104 const actual = matches.length;
105 return actual === expected
106 ? { disposition: 'verified', actual, expected, reason: 'exact count match' }
107 : { disposition: 'failed', actual, expected, reason: `count mismatch: claim=${expected}, actual=${actual}` };
108}
109
110async function verifyPatternExists(claim) {
111 const { file, pattern } = claim;

Callers 1

verifyClaimFunction · 0.85

Calls 2

readClaimFileFunction · 0.85
compilePatternFunction · 0.85

Tested by

no test coverage detected