Commit 9ddb189
authored
fix(reformat): reformat overwrites content (#4672)
This pull request fixes an issue where the current reformat logic could
unintentionally overwrite content following the `query` field in an
artifact. This most commonly affected artifacts that define additional
fields such as `notebook` or `column_types`.
For example, given the following artifact with a `notebook` field:
```yaml
name: Notebook
sources:
- query: |
SELECT A,B,C
FROM scope()
notebook:
- name: Test
type: vql_suggestion
template: |
SELECT * FROM scope()
```
Running the reformat command (either via CLI or the GUI) would remove
the `notebook:` line. Subsequent reformats would continue stripping
content, producing an invalid artifact such as:
```yaml
name: Notebook
sources:
- query: |
SELECT A,
B,
C
FROM scope()
- name: Test
type: vql_suggestion
template: |
SELECT * FROM scope()
```
> Error: While parsing VQL at line 8: unexpected token "-"
The root cause was an off-by-one error in the mutation logic applied to
the `query` block, which caused the reformat operation to extend beyond
the intended range. While addressing this, I also identified an issue
with how `original_end_line` was calculated for chomping indicator nodes
(`|-`). Because these nodes omit the trailing newline, splitting on `\n`
resulted in an incorrect end line calculation.
Additionally, the `current_mu.err` value was never checked when applying
mutations that only had a length of one. This has also been resolved by
adding an additional check at the beginning of the line iteration.
This change corrects these issues and adds regression tests to verify
that:
- Content following a `query` block is preserved.
- Running reformat multiple times produces stable, idempotent output.
Please let me know if you'd like further clarification, or if there are
any changes you'd like made.
I am also considering a refactor of the `artifacts reformat` to call a
`reformat` VQL function which wraps this functionality, following the
pattern that CLI commands are just wrappers around VQL. Let me know if
this is also something you'd be interested in me contributing. 😃1 parent 8d84532 commit 9ddb189
File tree
3 files changed
+90
-7
lines changed- services/repository
- fixtures
3 files changed
+90
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
| 34 | + | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| |||
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
42 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
43 | 76 | | |
44 | 77 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
88 | 94 | | |
89 | 95 | | |
90 | | - | |
91 | | - | |
92 | | - | |
| 96 | + | |
| 97 | + | |
93 | 98 | | |
94 | 99 | | |
95 | 100 | | |
| |||
103 | 108 | | |
104 | 109 | | |
105 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
106 | 115 | | |
107 | 116 | | |
108 | 117 | | |
| |||
111 | 120 | | |
112 | 121 | | |
113 | 122 | | |
| 123 | + | |
114 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
115 | 129 | | |
116 | 130 | | |
117 | | - | |
| 131 | + | |
118 | 132 | | |
119 | 133 | | |
120 | 134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
50 | 74 | | |
51 | 75 | | |
52 | 76 | | |
| |||
59 | 83 | | |
60 | 84 | | |
61 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
0 commit comments