Skip to content

Commit 94325b3

Browse files
test: promote optional reference regressions
1 parent 902f050 commit 94325b3

6 files changed

Lines changed: 242 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implement Java Optional fallback logic without eager fallback work or presence-check value reads.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"context": "Transcript-derived maintainability cleanup from Symphony for Trello: preserve workflow validation behavior while replacing repeated Optional reopening in a real implementation.",
3+
"type": "weighted_checklist",
4+
"checklist": [
5+
{
6+
"name": "Creates revised validation class",
7+
"category": "safety",
8+
"max_score": 5,
9+
"description": "Creates WorkflowConfigValidation.java with the requested class, imports, records, validate method, boardId method, and serverPort method."
10+
},
11+
{
12+
"name": "Uses Optional as validation boundary",
13+
"category": "optional_quality",
14+
"max_score": 30,
15+
"description": "Uses boardId(yaml).map(...).orElseGet(...) and serverPort(yaml).map(...).orElseGet(...) or an equivalent direct Optional boundary for validation."
16+
},
17+
{
18+
"name": "Removes Optional reopening",
19+
"category": "optional_quality",
20+
"max_score": 30,
21+
"description": "Does not keep isPresent()/isEmpty() followed by get() or orElseThrow() for configured board id or configured server port value reads."
22+
},
23+
{
24+
"name": "Avoids null/list workaround",
25+
"category": "optional_quality",
26+
"max_score": 20,
27+
"description": "Does not replace the Optionals with orElse(null), local null branching, Optional.stream().toList(), lists, or loops over a single Optional."
28+
},
29+
{
30+
"name": "Keeps readable helpers",
31+
"category": "maintainability",
32+
"max_score": 5,
33+
"description": "Extracts or uses clear helper methods for board-id validation and server-port validation, rather than embedding repeated warning construction and value reads in one long method."
34+
},
35+
{
36+
"name": "Preserves board-id behavior",
37+
"category": "safety",
38+
"max_score": 4,
39+
"description": "Accepts both board.boardId() and board.boardKey(), returns the missing tracker.board_id warning for absent/blank values, and returns the mismatch warning with expected id/key and found value."
40+
},
41+
{
42+
"name": "Preserves server-port behavior",
43+
"category": "safety",
44+
"max_score": 4,
45+
"description": "Accepts Number values and trimmed numeric String values, returns the missing server.port warning for absent/blank/malformed/unsupported values, and returns the mismatch warning with expected and found ports."
46+
},
47+
{
48+
"name": "Preserves success result",
49+
"category": "safety",
50+
"max_score": 2,
51+
"description": "Returns WorkflowValidation.valid() when both board id and server port match."
52+
}
53+
],
54+
"metadata": {
55+
"invocation": "explicit",
56+
"task_type": "implementation"
57+
}
58+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Finish workflow validation cleanup
2+
3+
Assume Java 17.
4+
5+
Use `$java-optionals` to create `WorkflowConfigValidation.java` with the revised class.
6+
7+
This is adapted from a real AI-assisted maintainability cleanup. The original task was a broad
8+
readability/refactor pass that had to preserve the same behavior. The code below works, but the
9+
validation method should be easier to maintain.
10+
11+
Current code:
12+
13+
```java
14+
import java.nio.file.Path;
15+
import java.util.Map;
16+
import java.util.Optional;
17+
18+
final class WorkflowConfigValidation {
19+
WorkflowValidation validate(ConnectedBoard board, Map<String, Object> yaml) {
20+
Optional<String> configuredBoardId = boardId(yaml);
21+
if (configuredBoardId.isEmpty()) {
22+
return WorkflowValidation.warn("Workflow file is missing tracker.board_id for \""
23+
+ board.boardName() + "\": " + board.workflowPath());
24+
}
25+
String boardId = configuredBoardId.orElseThrow();
26+
if (!boardId.equals(board.boardId()) && !boardId.equals(board.boardKey())) {
27+
return WorkflowValidation.warn("Workflow tracker.board_id does not match the connected board for \""
28+
+ board.boardName() + "\": expected " + board.boardId() + " or " + board.boardKey()
29+
+ " but found " + boardId);
30+
}
31+
Optional<Integer> configuredServerPort = serverPort(yaml);
32+
if (configuredServerPort.isEmpty()) {
33+
return WorkflowValidation.warn("Workflow file is missing server.port for \""
34+
+ board.boardName() + "\": " + board.workflowPath());
35+
}
36+
if (configuredServerPort.orElseThrow() != board.serverPort()) {
37+
return WorkflowValidation.warn("Workflow server.port does not match the connected board for \""
38+
+ board.boardName() + "\": expected " + board.serverPort() + " but found "
39+
+ configuredServerPort.orElseThrow());
40+
}
41+
return WorkflowValidation.valid();
42+
}
43+
44+
Optional<String> boardId(Map<String, Object> yaml) {
45+
Object trackerValue = yaml.get("tracker");
46+
if (!(trackerValue instanceof Map<?, ?> tracker)) {
47+
return Optional.empty();
48+
}
49+
Object value = tracker.get("board_id");
50+
String text = value == null ? null : String.valueOf(value);
51+
return text == null || text.isBlank() ? Optional.empty() : Optional.of(text);
52+
}
53+
54+
Optional<Integer> serverPort(Map<String, Object> yaml) {
55+
Object serverValue = yaml.get("server");
56+
if (!(serverValue instanceof Map<?, ?> server)) {
57+
return Optional.empty();
58+
}
59+
Object value = server.get("port");
60+
if (value instanceof Number number) {
61+
return Optional.of(number.intValue());
62+
}
63+
if (value instanceof String text && !text.isBlank()) {
64+
try {
65+
return Optional.of(Integer.parseInt(text.trim()));
66+
} catch (NumberFormatException ignored) {
67+
return Optional.empty();
68+
}
69+
}
70+
return Optional.empty();
71+
}
72+
73+
record ConnectedBoard(String boardName, String boardId, String boardKey, int serverPort, Path workflowPath) {}
74+
75+
record WorkflowValidation(boolean ok, String message) {
76+
static WorkflowValidation valid() { return new WorkflowValidation(true, ""); }
77+
static WorkflowValidation warn(String message) { return new WorkflowValidation(false, message); }
78+
}
79+
}
80+
```
81+
82+
Required changes:
83+
84+
- Keep the same warning messages and successful `WorkflowValidation.valid()` result.
85+
- Keep accepting `board.boardId()` and `board.boardKey()` as matching tracker board ids.
86+
- Keep accepting numeric server ports and trimmed numeric string server ports.
87+
- Return the missing-board warning when `tracker.board_id` is absent or blank.
88+
- Return the missing-port warning when `server.port` is absent, blank, malformed, or unsupported.
89+
- Leave `boardId(...)` and `serverPort(...)` returning `Optional`.
90+
- You may extract private helpers if that makes the validation flow clearer.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implement Java command sanitization while preserving exact output order and Optional match handling.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"context": "Representative real-collection lookup case: the option set is real data and matching should stay centralized while the outer loop handles redact-next state.",
3+
"type": "weighted_checklist",
4+
"checklist": [
5+
{
6+
"name": "Compiles and creates requested artifact",
7+
"category": "safety",
8+
"max_score": 5,
9+
"description": "Creates a coherent CommandSanitizer.java with sanitize(List<String>) and the required secret option set, using APIs compatible with the stated Java 17 baseline."
10+
},
11+
{
12+
"name": "Implements exact redaction behavior",
13+
"category": "safety",
14+
"max_score": 5,
15+
"description": "Preserves exact-option behavior such as --token abc -> --token <redacted>, adds option=value behavior such as --key=abc -> --key=<redacted>, and preserves non-secret arguments exactly."
16+
},
17+
{
18+
"name": "Preserves output order and sequence state",
19+
"category": "safety",
20+
"max_score": 5,
21+
"description": "Keeps output order, uses String.join(\" \", sanitized), and keeps redact-next behavior only for exact secret options."
22+
},
23+
{
24+
"name": "Keeps option matching centralized",
25+
"category": "maintainability",
26+
"max_score": 5,
27+
"description": "Keeps exact and option=value matching in one readable helper or direct lookup; a real Set stream, loop, or contains-based shape is acceptable when behavior remains clear."
28+
},
29+
{
30+
"name": "Consumes Optional result directly",
31+
"category": "optional_quality",
32+
"max_score": 45,
33+
"description": "Handles the match result with map/orElse or another direct Optional boundary rather than isPresent()/get() or orElseThrow() value reads."
34+
},
35+
{
36+
"name": "Avoids fake or noisy rewrites",
37+
"category": "optional_quality",
38+
"max_score": 35,
39+
"description": "Does not force a fake Optional collection, duplicate matching branches throughout the loop, local null sentinels, labels, or unnecessary nested loops."
40+
}
41+
],
42+
"metadata": {
43+
"invocation": "natural",
44+
"task_type": "implementation"
45+
}
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Extend command sanitization
2+
3+
Create `CommandSanitizer.java` with the revised class. Assume Java 17.
4+
5+
Current code:
6+
7+
```java
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
import java.util.Optional;
11+
import java.util.Set;
12+
13+
final class CommandSanitizer {
14+
private static final Set<String> SECRET_OPTIONS = Set.of("--token", "--key", "--workflow", "--config-dir", "--state-home", "--output");
15+
16+
String sanitize(List<String> args) {
17+
List<String> sanitized = new ArrayList<>();
18+
boolean redactNext = false;
19+
for (String arg : args) {
20+
if (redactNext) {
21+
sanitized.add("<redacted>");
22+
redactNext = false;
23+
continue;
24+
}
25+
Optional<String> option = SECRET_OPTIONS.stream()
26+
.filter(secret -> arg.equals(secret))
27+
.findFirst();
28+
if (option.isPresent()) {
29+
sanitized.add(option.orElseThrow());
30+
redactNext = true;
31+
} else {
32+
sanitized.add(arg);
33+
}
34+
}
35+
return String.join(" ", sanitized);
36+
}
37+
}
38+
```
39+
40+
Required changes:
41+
42+
- Preserve exact-option behavior: `--token abc` becomes `--token <redacted>`.
43+
- Add `option=value` behavior: `--key=abc` becomes `--key=<redacted>`.
44+
- Preserve non-secret arguments.
45+
- Keep the real option-set lookup readable and centralized.
46+
- Return `String.join(" ", sanitized)`.

0 commit comments

Comments
 (0)