Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fix quality metadata and fixedFindings for changeset entry #32

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add strategy and provisional metadata
  • Loading branch information
drdavella committed Dec 4, 2024
commit 2c112b5307e5fee0b0dbc87a6e34e41fcbf4fec4
24 changes: 20 additions & 4 deletions src/main/java/io/codemodder/codetf/CodeTFChangesetEntry.java
Original file line number Diff line number Diff line change
@@ -15,22 +15,28 @@ public final class CodeTFChangesetEntry {
private final List<CodeTFChange> changes;

private final CodeTFAiMetadata ai;
private final Strategy strategy;
private final boolean provisional;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the spec already calls for this to be a boolean, so I'm probably too late on this feedback, but replacing "boolean" with "enum that has two items" leaves room for expansion and better describes what this is e.g.

enum Maturity { MATURE, PROVISIONAL; }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, but at this point I think we will need to revisit it at a later date.


@JsonCreator
public CodeTFChangesetEntry(
@JsonProperty("path") final String path,
@JsonProperty("diff") final String diff,
@JsonProperty("changes") final List<CodeTFChange> changes,
@JsonProperty("ai") final CodeTFAiMetadata ai) {
@JsonProperty("ai") final CodeTFAiMetadata ai,
@JsonProperty("strategy") final Strategy strategy,
@JsonProperty("provisional") final boolean provisional) {
this.path = CodeTFValidator.requireRelativePath(path);
this.diff = CodeTFValidator.requireNonBlank(diff);
this.changes = CodeTFValidator.toImmutableCopyOrEmptyOnNull(changes);
this.ai = ai;
this.strategy = strategy;
this.provisional = provisional;
}

public CodeTFChangesetEntry(
final String path, final String diff, final List<CodeTFChange> changes) {
this(path, diff, changes, null);
this(path, diff, changes, null, null, false);
}

public String getPath() {
@@ -53,6 +59,14 @@ public boolean usesAi() {
return ai != null;
}

public Strategy getStrategy() {
return strategy;
}

public boolean isProvisional() {
return provisional;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -61,12 +75,14 @@ public boolean equals(Object o) {
return Objects.equals(path, entry.path)
&& Objects.equals(diff, entry.diff)
&& Objects.equals(changes, entry.changes)
&& Objects.equals(ai, entry.ai);
&& Objects.equals(ai, entry.ai)
&& Objects.equals(strategy, entry.strategy)
&& Objects.equals(provisional, entry.provisional);
}

@Override
public int hashCode() {
return Objects.hash(path, diff, changes, ai);
return Objects.hash(path, diff, changes, ai, strategy, provisional);
}

@Override
12 changes: 12 additions & 0 deletions src/main/java/io/codemodder/codetf/Strategy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.codemodder.codetf;

import com.fasterxml.jackson.annotation.JsonProperty;

public enum Strategy {
@JsonProperty("ai")
AI,
@JsonProperty("hybrid")
HYBRID,
@JsonProperty("deterministic")
DETERMINISTIC,
}
13 changes: 12 additions & 1 deletion src/test/java/io/codemodder/codetf/CodeTFResultTest.java
Original file line number Diff line number Diff line change
@@ -134,7 +134,8 @@ void it_creates_unfixed_findings() {
@Test
void it_has_changeset_with_ai() {
CodeTFAiMetadata ai = new CodeTFAiMetadata("ai", "best-model-ever", null);
CodeTFChangesetEntry entry = new CodeTFChangesetEntry("src/foo", "diff", List.of(), ai);
CodeTFChangesetEntry entry =
new CodeTFChangesetEntry("src/foo", "diff", List.of(), ai, null, false);
assertTrue(entry.usesAi());

final var result =
@@ -156,6 +157,16 @@ void it_has_changeset_with_ai() {
assertTrue(result.usesAi());
}

@Test
void it_has_changeset_with_fix_quality_metadata() {
CodeTFAiMetadata ai = new CodeTFAiMetadata("ai", "best-model-ever", null);
CodeTFChangesetEntry entry =
new CodeTFChangesetEntry("src/foo", "diff", List.of(), ai, Strategy.HYBRID, true);

assertEquals(entry.getStrategy(), Strategy.HYBRID);
assertTrue(entry.isProvisional());
}

@Test
void it_has_failure_state() {
Failure state = new Failure("reason", "exception");