<commit_before>package circlet.integration

import circlet.pipelines.config.api.*
import circlet.pipelines.config.dsl.api.*
import circlet.pipelines.config.dsl.script.exec.common.*
import circlet.plugins.pipelines.services.*
import circlet.plugins.pipelines.ui.*
import circlet.plugins.pipelines.viewmodel.*
import com.intellij.openapi.components.*
import com.intellij.testFramework.fixtures.*
import com.intellij.util.*
import runtime.reactive.*
import kotlin.test.*


class TestProjectExecutor(override val listener: ProjectElementListener) : ProjectExecutor {
    override val buildNumber: String = "test.0"
    override val vcsRevision: String = "revision.0"
    override val vcsBranch: String = "test"
}

private const val scriptFileName : String = "circlet.kts"

class SmokeTest : JavaCodeInsightFixtureTestCase() {

    private var testLifetimeImpl : LifetimeSource? = null

    private val testLifetime: Lifetime
        get() = testLifetimeImpl!!

    override fun setUp() {
        testLifetimeImpl = Lifetime.Eternal.nested()
        super.setUp()
    }

    override fun tearDown() {
        super.tearDown()
        testLifetimeImpl!!.terminate()
    }

    override fun getTestDataPath(): String {
        return "src/test/resources/integrationTestGold"
    }

    // dsl exist on start
    fun testBuildModelWhenDslExistsFromBeginning() {
        val project = myFixture.project
        val projectFileFolderName = PathUtil.getFileName(project.basePath!!)
        myFixture.copyFileToProject(scriptFileName, "../$projectFileFolderName/$scriptFileName")

        val circletModelStore = ServiceManager.getService(project, CircletModelStore::class.java)
        val viewModel = circletModelStore.viewModel

        var script = viewModel.script.value
        assertNotNull(script, "script should be not null at init")
        assertTrue(script.isScriptEmpty(), "script should be empty at init")
        assertFalse(viewModel.modelBuildIsRunning.value, "model build should not be started until view is shown")

        val view = CircletScriptsViewFactory().createView(testLifetime, project, viewModel)

        assertNotNull(view, "view should not be null")
        assertFalse(viewModel.modelBuildIsRunning.value, "test run in sync mode. so model build should be finished")
        val newScript = viewModel.script.value
        assertNotNull(newScript, "script should be not null after build")
        assertNotSame(script, newScript, "new instance of script should be created")
        script = newScript
        assertFalse(script.isScriptEmpty(), "script should not be empty after build")

        assertEquals(createGoldModel(), script.config)
    }

    private fun ScriptViewModel.isScriptEmpty(): Boolean {
        val config = this.config
        return config.pipelines.isEmpty() && config.targets.isEmpty() && config.tasks.isEmpty()
    }

    private fun createGoldModel() : ProjectConfig {
        val projectElementListener = ProjectConfigBuilder()
        val executor = TestProjectExecutor(projectElementListener)

        object : circlet.pipelines.config.dsl.api.Project(executor) {
            init {
                task("myTask") {
                    fork {
                        run("hello-world1")
                        run("hello-world2")
                    }
                }
            }
        }

        return projectElementListener.build()
    }
}<commit_msg>[idea plugin] [automation] one more test<commit_after>package circlet.integration

import circlet.pipelines.config.api.*
import circlet.pipelines.config.dsl.api.*
import circlet.pipelines.config.dsl.script.exec.common.*
import circlet.plugins.pipelines.services.*
import circlet.plugins.pipelines.ui.*
import circlet.plugins.pipelines.viewmodel.*
import com.intellij.openapi.components.*
import com.intellij.testFramework.fixtures.*
import com.intellij.util.*
import runtime.reactive.*
import kotlin.test.*


class TestProjectExecutor(override val listener: ProjectElementListener) : ProjectExecutor {
    override val buildNumber: String = "test.0"
    override val vcsRevision: String = "revision.0"
    override val vcsBranch: String = "test"
}

private const val scriptFileName : String = "circlet.kts"

class SmokeTest : JavaCodeInsightFixtureTestCase() {

    private var testLifetimeImpl : LifetimeSource? = null

    private val testLifetime: Lifetime
        get() = testLifetimeImpl!!

    override fun setUp() {
        testLifetimeImpl = Lifetime.Eternal.nested()
        super.setUp()
    }

    override fun tearDown() {
        super.tearDown()
        testLifetimeImpl!!.terminate()
    }

    override fun getTestDataPath(): String {
        return "src/test/resources/integrationTestGold"
    }

    // dsl exists on start
    fun testBuildModelWhenDslExistsFromBeginning() {
        val project = myFixture.project
        val projectFileFolderName = PathUtil.getFileName(project.basePath!!)
        myFixture.copyFileToProject(scriptFileName, "../$projectFileFolderName/$scriptFileName")

        val circletModelStore = ServiceManager.getService(project, CircletModelStore::class.java)
        val viewModel = circletModelStore.viewModel

        var script = viewModel.script.value
        assertNotNull(script, "script should be not null at init")
        assertTrue(script.isScriptEmpty(), "script should be empty at init")
        assertFalse(viewModel.modelBuildIsRunning.value, "model build should not be started until view is shown")

        val view = CircletScriptsViewFactory().createView(testLifetime, project, viewModel)

        assertNotNull(view, "view should not be null")
        assertFalse(viewModel.modelBuildIsRunning.value, "test run in sync mode. so model build should be finished")
        val newScript = viewModel.script.value
        assertNotNull(newScript, "script should be not null after build")
        assertNotSame(script, newScript, "new instance of script should be created")
        script = newScript
        assertFalse(script.isScriptEmpty(), "script should not be empty after build")

        assertEquals(createGoldModel(), script.config)
    }

    // dsl doesnt exist on start and added later
    fun testBuildModelWhenDslDoesnotExistFromBeginning() {
        val project = myFixture.project

        val circletModelStore = ServiceManager.getService(project, CircletModelStore::class.java)
        val viewModel = circletModelStore.viewModel

        var script = viewModel.script.value
        assertNull(script, "script should be null without dsl file")
        assertFalse(viewModel.modelBuildIsRunning.value, "model build should not be started until view is shown")

        val projectFileFolderName = PathUtil.getFileName(project.basePath!!)
        myFixture.copyFileToProject(scriptFileName, "../$projectFileFolderName/$scriptFileName")

        val newScript = viewModel.script.value
        assertNotSame(script, newScript, "new instance of script should be created")
        script = newScript
        assertNotNull(script, "script should be not null after added dsl")
        assertTrue(script.isScriptEmpty(), "script should be empty after added dsl")
    }

    private fun ScriptViewModel.isScriptEmpty(): Boolean {
        val config = this.config
        return config.pipelines.isEmpty() && config.targets.isEmpty() && config.tasks.isEmpty()
    }

    private fun createGoldModel() : ProjectConfig {
        val projectElementListener = ProjectConfigBuilder()
        val executor = TestProjectExecutor(projectElementListener)

        object : circlet.pipelines.config.dsl.api.Project(executor) {
            init {
                task("myTask") {
                    fork {
                        run("hello-world1")
                        run("hello-world2")
                    }
                }
            }
        }

        return projectElementListener.build()
    }
}
{'fraction_non_alphanumeric': 0.08844055322928562, 'fraction_numerical': 0.0010150996066489023, 'mean_word_length': 3.081822889694459, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7588783', 'n_tokens_mistral': 2117, 'n_tokens_neox': 2035, 'n_words': 517}