@mytegroupinc/myte-core 0.0.49 → 0.0.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,6 +21,12 @@ const ROUTE_MATRIX = [
21
21
  { id: "feedback-prd-versions", kind: "read", mutation: "none", conditional: "feedback_id" },
22
22
  { id: "feedback-prd-diff", kind: "read", mutation: "none", conditional: "version_id" },
23
23
  { id: "query", kind: "inference-job", mutation: "ephemeral_job", conditional: "--include-query" },
24
+ {
25
+ id: "query-with-diff",
26
+ kind: "inference-job",
27
+ mutation: "temporary_tracked_fixture_and_ephemeral_job",
28
+ conditional: "--include-diff-query",
29
+ },
24
30
  ];
25
31
 
26
32
  function parseArgs(argv) {
@@ -87,6 +93,189 @@ function runCli(args, { cwd, timeoutMs = 360000 } = {}) {
87
93
  };
88
94
  }
89
95
 
96
+ function runGit(args, cwd) {
97
+ const result = spawnSync("git", args, {
98
+ cwd,
99
+ env: process.env,
100
+ encoding: "utf8",
101
+ timeout: 60000,
102
+ stdio: ["ignore", "pipe", "pipe"],
103
+ });
104
+ return {
105
+ ok: result.status === 0,
106
+ exit_code: result.status,
107
+ stdout: String(result.stdout || ""),
108
+ stderr: String(result.stderr || "").trim(),
109
+ };
110
+ }
111
+
112
+ function resolveDiffFixture(configData) {
113
+ const local = configData?.local && typeof configData.local === "object"
114
+ ? configData.local
115
+ : {};
116
+ const root = String(local.root || "").trim();
117
+ const found = Array.isArray(local.found) ? local.found.map(String) : [];
118
+ if (!root || !found.length) {
119
+ throw new Error("Diff certification requires at least one resolved configured repository.");
120
+ }
121
+
122
+ for (const repoName of found) {
123
+ const repoPath = path.resolve(root, repoName);
124
+ const status = runGit(["status", "--porcelain"], repoPath);
125
+ if (!status.ok || status.stdout.trim()) continue;
126
+
127
+ const tracked = runGit(["ls-files"], repoPath);
128
+ if (!tracked.ok) continue;
129
+ const candidates = tracked.stdout
130
+ .split(/\r?\n/)
131
+ .map((item) => item.trim())
132
+ .filter(Boolean)
133
+ .filter((item) => /(^|\/)readme(?:\.[a-z0-9]+)?$/i.test(item));
134
+ for (const relativePath of candidates) {
135
+ const filePath = path.resolve(repoPath, relativePath);
136
+ if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
137
+ return {
138
+ repoName,
139
+ repoPath,
140
+ relativePath,
141
+ filePath,
142
+ };
143
+ }
144
+ }
145
+ }
146
+ throw new Error(
147
+ "Diff certification requires a clean configured repository with a tracked README file.",
148
+ );
149
+ }
150
+
151
+ function runDiffCertification({
152
+ args,
153
+ configData,
154
+ runId,
155
+ workspace,
156
+ shared,
157
+ }) {
158
+ const fixture = resolveDiffFixture(configData);
159
+ const marker = `MYTE_CERT_DIFF_${runId.replace(/[^A-Za-z0-9_]/g, "_")}`;
160
+ const original = fs.readFileSync(fixture.filePath);
161
+ const originalStatus = runGit(["status", "--porcelain"], fixture.repoPath);
162
+ let contextCheck = null;
163
+ let queryCheck = null;
164
+ let restoreError = null;
165
+
166
+ try {
167
+ const separator = original.length && !original.toString("utf8").endsWith("\n")
168
+ ? "\n"
169
+ : "";
170
+ fs.appendFileSync(
171
+ fixture.filePath,
172
+ `${separator}\n<!-- ${marker} -->\n`,
173
+ "utf8",
174
+ );
175
+ const diffLimit = String(args["diff-limit"] || 500000);
176
+ const prompt = [
177
+ "Goal: certify project-scoped diff ingestion.",
178
+ `Evidence marker: ${marker}.`,
179
+ `Ask: return the exact marker and name ${fixture.repoName}/${fixture.relativePath}.`,
180
+ ].join(" ");
181
+ const commonDiffArgs = [
182
+ "query",
183
+ prompt,
184
+ "--with-diff",
185
+ "--no-fetch",
186
+ "--diff-limit",
187
+ diffLimit,
188
+ ...shared,
189
+ ];
190
+ const rawContextCheck = runCli(
191
+ [...commonDiffArgs, "--print-context"],
192
+ { cwd: workspace },
193
+ );
194
+ const contextText = Array.isArray(rawContextCheck.data?.additional_context)
195
+ ? rawContextCheck.data.additional_context.join("\n")
196
+ : "";
197
+ const markerPresent = contextText.includes(marker);
198
+ const fetchDisabled =
199
+ rawContextCheck.data?.diff_diagnostics?.fetch_remote === false;
200
+ contextCheck = {
201
+ ...rawContextCheck,
202
+ id: "query-with-diff-context",
203
+ command: "myte query <redacted> --with-diff --print-context",
204
+ ok: rawContextCheck.ok && markerPresent && fetchDisabled,
205
+ error: rawContextCheck.ok && markerPresent && fetchDisabled
206
+ ? null
207
+ : rawContextCheck.error
208
+ || "Diff context did not contain the marker or --no-fetch was not honored.",
209
+ data: {
210
+ marker_present: markerPresent,
211
+ fetch_remote: rawContextCheck.data?.diff_diagnostics?.fetch_remote,
212
+ truncated: rawContextCheck.data?.diff_diagnostics?.truncated,
213
+ fixture_repo: fixture.repoName,
214
+ fixture_file: fixture.relativePath,
215
+ },
216
+ };
217
+
218
+ if (contextCheck.ok) {
219
+ const rawQueryCheck = runCli(
220
+ [
221
+ ...commonDiffArgs,
222
+ "--request-id",
223
+ `cert-diff-${runId}`.slice(0, 128),
224
+ "--json",
225
+ ],
226
+ { cwd: workspace },
227
+ );
228
+ const answer = String(rawQueryCheck.data?.answer || "");
229
+ const answerContainsMarker = answer.includes(marker);
230
+ queryCheck = {
231
+ ...rawQueryCheck,
232
+ id: "query-with-diff",
233
+ command: "myte query <redacted> --with-diff",
234
+ ok: rawQueryCheck.ok && answerContainsMarker,
235
+ error: rawQueryCheck.ok && answerContainsMarker
236
+ ? null
237
+ : rawQueryCheck.error
238
+ || "Live diff-query answer did not contain the exact fixture marker.",
239
+ data: {
240
+ marker_present_in_answer: answerContainsMarker,
241
+ job_id: rawQueryCheck.data?.job_id || null,
242
+ request_id: rawQueryCheck.data?.request_id || null,
243
+ },
244
+ };
245
+ }
246
+ } finally {
247
+ try {
248
+ fs.writeFileSync(fixture.filePath, original);
249
+ const restoredStatus = runGit(["status", "--porcelain"], fixture.repoPath);
250
+ if (
251
+ !restoredStatus.ok
252
+ || restoredStatus.stdout !== originalStatus.stdout
253
+ ) {
254
+ restoreError = "Diff fixture repository did not return to its original clean status.";
255
+ }
256
+ } catch (error) {
257
+ restoreError = error?.message || String(error);
258
+ }
259
+ }
260
+
261
+ const checks = [];
262
+ if (contextCheck) checks.push(contextCheck);
263
+ if (queryCheck) checks.push(queryCheck);
264
+ checks.push({
265
+ id: "query-with-diff-fixture-restore",
266
+ command: "restore temporary tracked diff fixture",
267
+ ok: !restoreError,
268
+ exit_code: restoreError ? 1 : 0,
269
+ duration_ms: 0,
270
+ data: {
271
+ fixture_repo: fixture.repoName,
272
+ fixture_file: fixture.relativePath,
273
+ },
274
+ error: restoreError,
275
+ });
276
+ return checks;
277
+ }
278
+
90
279
  function firstFeedbackId(feedbackPath) {
91
280
  if (!fs.existsSync(feedbackPath)) return null;
92
281
  const text = fs.readFileSync(feedbackPath, "utf8");
@@ -176,7 +365,8 @@ function main() {
176
365
  process.exit(1);
177
366
  }
178
367
 
179
- checks.push(runCli(["config", "--json", ...shared], { cwd: workspace }));
368
+ const config = runCli(["config", "--json", ...shared], { cwd: workspace });
369
+ checks.push(config);
180
370
  checks.push(runCli(["bootstrap", "--output-dir", outputDir, "--json", ...shared], { cwd: workspace }));
181
371
  checks.push(runCli(["feedback-sync", "--output-dir", outputDir, "--json", ...shared], { cwd: workspace }));
182
372
  checks.push(runCli(["sync-qaqc", "--output-dir", outputDir, "--json", ...shared], { cwd: workspace }));
@@ -230,6 +420,28 @@ function main() {
230
420
  ], { cwd: workspace }));
231
421
  }
232
422
 
423
+ if (args["include-diff-query"]) {
424
+ if (!config.ok) {
425
+ checks.push({
426
+ id: "query-with-diff",
427
+ command: "myte query <redacted> --with-diff",
428
+ ok: false,
429
+ exit_code: 1,
430
+ duration_ms: 0,
431
+ data: null,
432
+ error: "Project config failed; diff certification could not resolve a repository.",
433
+ });
434
+ } else {
435
+ checks.push(...runDiffCertification({
436
+ args,
437
+ configData: config.data,
438
+ runId,
439
+ workspace,
440
+ shared,
441
+ }));
442
+ }
443
+ }
444
+
233
445
  const failed = checks.filter((check) => !check.ok);
234
446
  console.log(JSON.stringify({
235
447
  ok: failed.length === 0,