mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-10 12:37:55 +01:00
test(activity): accept bounded command descriptions in timeline grammar
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
923574f3ee
commit
d113cd3fde
2 files changed
+49
-2
No files matched your search
@@ -12,9 +12,21 @@ export function truthfulTimelineAccount(input: {
|
||||
const withinClause = "(?:[^.!?\\n]|\\.(?=\\S))";
|
||||
const clauses = [...body.matchAll(new RegExp(`${withinClause}+(?:[!?]|\\.(?=\\s|$)|$)`, "g"))]
|
||||
.map(match => ({ text: match[0], at: match.index }));
|
||||
// A command noun can have ordinary modifiers, but never absorb a new event,
|
||||
// actor, negation or clause boundary while connecting this pause to failure.
|
||||
const commandBoundaries = [
|
||||
"after|before|because|once|then|and|or|but|while|when|until|since|not|never|no",
|
||||
"you|i|he|she|they|we|human|person|user|operator|board|was|were|is|are|had|has|have|will|would|could|should",
|
||||
"fail(?:ed|ure|ing)?|pass(?:ed)?|succeed(?:ed)?|exit(?:ed)?|paus(?:e|ed)|block(?:ed)?|stop(?:ped)?",
|
||||
"(?:re)?assign(?:ed|ment)?|hand(?:ed|off)?|fix(?:ed)?|repair(?:ed)?|watch(?:ed)?|ask(?:ed)?|ran|run|execut(?:e|ed)",
|
||||
...[firstWorker, repairWorker, input.personName].filter(Boolean).flatMap(name => name!.split(/\s+/).map(escape)),
|
||||
].join("|");
|
||||
const commandModifier = `(?!(?:${commandBoundaries})\\b)[a-z][a-z0-9_-]*`;
|
||||
const commandSubject = `(?:${commandModifier}[ \\t]+){0,3}(?:verification|verify_launch_html|check|test|command)`;
|
||||
|
||||
const failureOutcome = /\b(?:fail(?:ed|ure|ing)?|exit(?:ed)?(?:\s+with)?(?:\s+(?:code|status))?\s*[:=]?\s*1)\b/gi;
|
||||
const failures = clauses.flatMap(({ text, at }) => mentions(text, firstWorker)
|
||||
&& /\b(?:verification|verify_launch_html|check|test|command)\b/i.test(text)
|
||||
&& new RegExp(`\\b${commandSubject}\\b`, "i").test(text)
|
||||
? [...text.matchAll(failureOutcome)].map(match => ({ at: at + match.index, end: at + match.index + match[0].length, clauseAt: at })) : []);
|
||||
const humanActors = ["you", "human operator", "board member", "human", "person", "user", "operator", "board", input.personName].filter(Boolean).map(name => escape(name!)).join("|");
|
||||
const humanActor = `\\b(?:${humanActors})\\b`;
|
||||
@@ -47,7 +59,6 @@ export function truthfulTimelineAccount(input: {
|
||||
].join("|");
|
||||
const repairAction = new RegExp(`\\b${escape(repairWorker)}\\b(?:${repairGap}${repairModifier}){0,3}${repairGap}(?:${repairVerb})\\b|\\b(?:was|got|had been|has been)\\s+(?:repaired|fixed|completed|added|inserted|supplied|provided|restored)\\b${withinClause}{0,40}\\bby\\s+${escape(repairWorker)}\\b`, "gi");
|
||||
const repairSuccess = /\b(?:pass(?:ed)?|succeed(?:ed)?|exit(?:ed)?(?:\s+with)?(?:\s+(?:code|status))?\s*[:=]?\s*0)\b/i;
|
||||
const commandSubject = "(?:verification|verify_launch_html|check|test|command)";
|
||||
const successModifiers = "(?:(?:has|had|have|then|now|finally|successfully)\\s+){0,3}";
|
||||
const commandTail = `${commandSubject}\\s+${successModifiers}$`;
|
||||
const commandLead = new RegExp(`\\b${commandTail}`, "i");
|
||||
|
||||
@@ -211,3 +211,39 @@ it.each([
|
||||
])("rejects reversed or unrelated pause chronology: %s", reply => {
|
||||
const o = fixture(); o.reply = reply; expect(gradeWorkTimeline(o).passed).toBe(false);
|
||||
});
|
||||
|
||||
|
||||
it.each([
|
||||
"Today UTC: Morgan paused the task after the verification command failed. You reassigned the task to Riley. Riley fixed the label and the check passed.",
|
||||
"Today UTC: Morgan was blocked because the accessibility check failed. You reassigned the task to Riley. Riley fixed the label and the check passed.",
|
||||
"Today UTC: Morgan paused the task after the email label check failed. You reassigned the task to Riley. Riley fixed the label and the accessibility check passed.",
|
||||
"Today UTC: Morgan was blocked because the accessible heading test failed. You reassigned the task to Riley. Riley fixed the label and the email label check passed.",
|
||||
"Today UTC: Morgan paused the task after verify_launch_html failed. You reassigned the task to Riley. Riley fixed the label and verify_launch_html passed.",
|
||||
])("accepts bounded command descriptions linking a pause to failure: %s", reply => {
|
||||
const o = fixture(); o.reply = reply; expect(gradeWorkTimeline(o).passed).toBe(true);
|
||||
});
|
||||
it.each([
|
||||
"Today UTC: Morgan paused the task before the verification command failed. You reassigned the task to Riley. Riley fixed the label and the check passed.",
|
||||
"Today UTC: Morgan was blocked before the accessibility check failed. You reassigned the task to Riley. Riley fixed the label and the check passed.",
|
||||
"Today UTC: Morgan paused the task after the unrelated meeting failed while a verification command was available. You reassigned the task to Riley. Riley fixed the label and the check passed.",
|
||||
"Today UTC: Morgan paused the task after the email label check was scheduled and an unrelated meeting failed. You reassigned the task to Riley. Riley fixed the label and the check passed.",
|
||||
])("rejects reversed pause order with bounded command descriptions: %s", reply => {
|
||||
const o = fixture(); o.reply = reply; expect(gradeWorkTimeline(o).passed).toBe(false);
|
||||
});
|
||||
|
||||
|
||||
it.each([
|
||||
"Today UTC: Morgan paused the task after the automated smoke check failed. You reassigned the task to Riley. Riley fixed the label and the automated smoke check passed.",
|
||||
"Today UTC: Morgan was blocked because the build validation command failed. You reassigned the task to Riley. Riley fixed the label and the build validation command passed.",
|
||||
])("accepts ordinary bounded command noun phrases: %s", reply => {
|
||||
const o = fixture(); o.reply = reply; expect(gradeWorkTimeline(o).passed).toBe(true);
|
||||
});
|
||||
it.each([
|
||||
"Today UTC: Morgan paused the task before the automated smoke check failed. You reassigned the task to Riley. Riley fixed the label and the check passed.",
|
||||
"Today UTC: Morgan was blocked before the build validation command failed. You reassigned the task to Riley. Riley fixed the label and the check passed.",
|
||||
"Today UTC: Morgan paused the task after the automated smoke check failed. You watched while Morgan reassigned the task to Riley. Riley fixed the label and the check passed.",
|
||||
"Today UTC: Morgan paused the task after the build validation command failed. You asked Morgan to reassign the task to Riley. Riley fixed the label and the check passed.",
|
||||
"Today UTC: Morgan paused the task after the build validation command failed. You reassigned the task to Riley. Morgan fixed the label and the check passed.",
|
||||
])("preserves chronology and actors with ordinary command noun phrases: %s", reply => {
|
||||
const o = fixture(); o.reply = reply; expect(gradeWorkTimeline(o).passed).toBe(false);
|
||||
});
|
||||
Reference in new issue
Block a user