chore(clean up): remove unused imports, unnecessary object impls, concurrency/coroutine issues, trailing commas, etc.

This commit is contained in:
2026-05-24 22:56:19 +04:00
parent 71aac8afc9
commit ac05ad8733
16 changed files with 85 additions and 83 deletions
@@ -7,6 +7,7 @@ import com.correx.core.artifacts.kind.FileWrittenPayload
import com.correx.infrastructure.artifactscas.segment.SegmentLayout
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.nio.file.Files
import java.nio.file.Path
@@ -15,7 +16,7 @@ import java.nio.file.attribute.PosixFilePermissions
class DefaultMaterializingArtifactWriter : MaterializingArtifactWriter {
private companion object {
val log = LoggerFactory.getLogger(DefaultMaterializingArtifactWriter::class.java)
val log: Logger = LoggerFactory.getLogger(DefaultMaterializingArtifactWriter::class.java)
const val DEFAULT_MODE = "644"
const val OCTAL_RADIX = 8
const val POSIX_PERMISSION_BITS = 9
@@ -37,21 +37,23 @@ class TailScanner(
private suspend fun scanAndRecover(activeId: Long, path: Path, startOffset: Long): TailScanReport {
var recovered = 0
var truncatedAt: Long? = null
RandomAccessFile(path.toFile(), "rw").use { raf ->
val fileLen = raf.length()
var pos = startOffset
while (pos < fileLen) {
val step = tryReadRecord(raf, pos, fileLen)
if (step == null) {
truncatedAt = pos
break
withContext(Dispatchers.IO) {
RandomAccessFile(path.toFile(), "rw").use { raf ->
val fileLen = raf.length()
var pos = startOffset
while (pos < fileLen) {
val step = tryReadRecord(raf, pos, fileLen)
if (step == null) {
truncatedAt = pos
break
}
index.insert(step.hash, Location(activeId, pos, step.length))
recovered += 1
pos += SegmentLayout.HEADER_SIZE + step.length
}
index.insert(step.hash, Location(activeId, pos, step.length))
recovered += 1
pos += SegmentLayout.HEADER_SIZE + step.length
// Truncate at first bad/partial record so writer resumes at a clean boundary.
truncatedAt?.let { raf.setLength(it) }
}
// Truncate at first bad/partial record so writer resumes at a clean boundary.
truncatedAt?.let { raf.setLength(it) }
}
return TailScanReport(activeId, startOffset, recovered, truncatedAt)
}
@@ -25,7 +25,7 @@ import java.util.concurrent.*
class LiveArtifactRepository(
private val eventStore: EventStore,
private val reducer: ArtifactReducer,
reducer: ArtifactReducer,
private val scope: CoroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob()),
) : ArtifactRepository {
@@ -41,8 +41,8 @@ class LiveArtifactRepository(
override fun getByStage(sessionId: SessionId, stageId: StageId): Map<ArtifactId, ArtifactState> {
ensureSubscribed(sessionId)
val cache = artifactCache[sessionId] ?: emptyMap<ArtifactId, ArtifactState>()
val index = stageIndex[sessionId] ?: emptyMap<ArtifactId, StageId>()
val cache = artifactCache[sessionId] ?: emptyMap()
val index = stageIndex[sessionId] ?: emptyMap()
return cache.filter { (artifactId, _) -> index[artifactId] == stageId }
}
@@ -24,6 +24,7 @@ import kotlinx.serialization.json.buildJsonArray
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
import kotlinx.serialization.json.putJsonObject
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.io.IOException
import java.nio.file.Files
@@ -40,7 +41,7 @@ class FileWriteTool(
) : Tool, FileAffectingTool, ToolExecutor {
private companion object {
val log = LoggerFactory.getLogger(FileWriteTool::class.java)
val log: Logger = LoggerFactory.getLogger(FileWriteTool::class.java)
}
private val normalizedAllowedPaths: Set<Path> = allowedPaths.map { it.normalize().toAbsolutePath() }.toSet()
@@ -172,7 +173,9 @@ class FileWriteTool(
): ToolResult = when (operation) {
"write" -> {
val content = request.parameters["content"] as String
Files.writeString(path, content)
withContext(Dispatchers.IO) {
Files.writeString(path, content)
}
storeArtifact(pathString, content, request.parameters["mode"] as? String ?: "0644")
ToolResult.Success(
invocationId = request.invocationId,
@@ -182,7 +185,9 @@ class FileWriteTool(
"delete" -> {
if (Files.exists(path)) {
Files.deleteIfExists(path)
withContext(Dispatchers.IO) {
Files.deleteIfExists(path)
}
ToolResult.Success(
invocationId = request.invocationId,
output = "File deleted successfully: $pathString",
@@ -145,7 +145,7 @@ class FileWriteToolTest {
assertTrue(result is ToolResult.Success)
val success = result as ToolResult.Success
assertEquals("File written successfully to ${filePath}", success.output)
assertEquals("File written successfully to $filePath", success.output)
assertEquals(invocationId, success.invocationId)
assertEquals(content, Files.readString(filePath))
}