Skip to content

Commit 68a7127

Browse files
committed
codex: address PR review feedback (#1129)
1 parent d9a0b50 commit 68a7127

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

src/preflight/collectChoiceRequirements.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ const {
1212
getMarkdownFilesWithTagMock,
1313
getUserScriptMock,
1414
isFolderMock,
15+
logWarningMock,
1516
} = vi.hoisted(() => ({
1617
getMarkdownFilesInFolderMock: vi.fn(() => []),
1718
getMarkdownFilesWithTagMock: vi.fn(() => []),
1819
getUserScriptMock: vi.fn(),
1920
isFolderMock: vi.fn(() => false),
21+
logWarningMock: vi.fn(),
2022
}));
2123

2224
vi.mock("src/utilityObsidian", () => ({
@@ -26,6 +28,12 @@ vi.mock("src/utilityObsidian", () => ({
2628
isFolder: isFolderMock,
2729
}));
2830

31+
vi.mock("src/logger/logManager", () => ({
32+
log: {
33+
logWarning: logWarningMock,
34+
},
35+
}));
36+
2937
function createMacroChoice(script: IUserScript): IMacroChoice {
3038
return {
3139
id: "macro-choice",
@@ -101,6 +109,7 @@ describe("collectChoiceRequirements - macro script metadata", () => {
101109
getMarkdownFilesWithTagMock.mockReset();
102110
getUserScriptMock.mockReset();
103111
isFolderMock.mockReset();
112+
logWarningMock.mockReset();
104113
getMarkdownFilesInFolderMock.mockReturnValue([]);
105114
getMarkdownFilesWithTagMock.mockReturnValue([]);
106115
isFolderMock.mockReturnValue(false);
@@ -178,6 +187,24 @@ describe("collectChoiceRequirements - macro script metadata", () => {
178187

179188
expect(requirements).toEqual([]);
180189
});
190+
191+
it("logs a warning when script metadata cannot be inspected", async () => {
192+
getUserScriptMock.mockRejectedValue(new Error("script load failed"));
193+
194+
const requirements = await collectChoiceRequirements(
195+
app,
196+
plugin,
197+
choiceExecutor,
198+
createMacroChoice(scriptCommand),
199+
);
200+
201+
expect(requirements).toEqual([]);
202+
expect(logWarningMock).toHaveBeenCalledWith(
203+
expect.stringContaining(
204+
"Preflight could not inspect user script 'script.js'",
205+
),
206+
);
207+
});
181208
});
182209

183210
describe("collectChoiceRequirements - capture targets", () => {
@@ -198,6 +225,7 @@ describe("collectChoiceRequirements - capture targets", () => {
198225
getMarkdownFilesInFolderMock.mockReset();
199226
getMarkdownFilesWithTagMock.mockReset();
200227
isFolderMock.mockReset();
228+
logWarningMock.mockReset();
201229
getMarkdownFilesInFolderMock.mockReturnValue([]);
202230
getMarkdownFilesWithTagMock.mockReturnValue([]);
203231
});
@@ -217,4 +245,23 @@ describe("collectChoiceRequirements - capture targets", () => {
217245
"Projects/",
218246
);
219247
});
248+
249+
it("does not force capture target dropdown for tokenized file paths", async () => {
250+
isFolderMock.mockReturnValue(false);
251+
252+
const requirements = await collectChoiceRequirements(
253+
app,
254+
plugin,
255+
choiceExecutor,
256+
createCaptureChoice("Projects/{{VALUE}}.md"),
257+
);
258+
259+
expect(getMarkdownFilesInFolderMock).not.toHaveBeenCalled();
260+
expect(
261+
requirements.some(
262+
(requirement) =>
263+
requirement.id === "QA_INTERNAL_CAPTURE_TARGET_FILE_PATH",
264+
),
265+
).toBe(false);
266+
});
220267
});

src/preflight/collectChoiceRequirements.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
getUserScript,
2222
isFolder,
2323
} from "src/utilityObsidian";
24+
import { log } from "src/logger/logManager";
2425
import { resolveExistingVariableKey } from "src/utils/valueSyntax";
2526
import {
2627
RequirementCollector,
@@ -174,14 +175,12 @@ async function collectForCaptureChoice(
174175
const isFolderTarget =
175176
!isTagTarget && (normalizedTarget === "" || isFolder(app, trimmedPath));
176177
const looksLikeFolderBySuffix = normalizedTarget.endsWith("/");
177-
const containsFormatTokens = /{{[^}]+}}/.test(choice.captureTo ?? "");
178178

179179
if (
180180
!choice.captureToActiveFile &&
181181
(isTagTarget ||
182182
isFolderTarget ||
183-
looksLikeFolderBySuffix ||
184-
containsFormatTokens)
183+
looksLikeFolderBySuffix)
185184
) {
186185
let files: TFile[] = [];
187186
if (isTagTarget) {
@@ -244,8 +243,13 @@ async function collectMacroScriptRequirements(
244243
const requirement = toFieldRequirement(input);
245244
if (requirement) requirements.push(requirement);
246245
}
247-
} catch {
248-
// Ignore script spec errors in preflight collection.
246+
} catch (error) {
247+
const scriptPath = userScriptCommand.path ?? userScriptCommand.id;
248+
const message =
249+
error instanceof Error ? error.message : String(error);
250+
log.logWarning(
251+
`Preflight could not inspect user script '${scriptPath}': ${message}`,
252+
);
249253
}
250254
}
251255

0 commit comments

Comments
 (0)