<commit_before>package integrate

import (
	"os"
	"testing"

	"github.com/itchio/butler/butlerd"
	"github.com/itchio/butler/butlerd/messages"
	itchio "github.com/itchio/go-itchio"
	"github.com/stretchr/testify/assert"
)

func Test_InstallUpdate(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping test in short mode")
	}

	log := func(msg string) {
		t.Logf("==========================")
		t.Logf("= %s", msg)
		t.Logf("==========================")
	}

	log("connecting to butlerd")

	rc, h, cancel := connect(t)
	defer cancel()

	authenticate(t, rc)
	setupTmpInstallLocation(t, h, rc)

	{
		log("listing builds...")

		// fasterthanlime/butler
		game := getGame(t, h, rc, 239683)

		client := itchio.ClientWithKey(os.Getenv("ITCH_TEST_ACCOUNT_API_KEY"))
		res, err := client.ListGameUploads(&itchio.ListGameUploadsParams{
			GameID: game.ID,
		})
		must(t, err)

		var upload *itchio.Upload
		for _, u := range res.Uploads {
			if u.ChannelName == "darwin-amd64-head" {
				upload = u
				break
			}
		}
		assert.NotNil(t, upload)

		buildsRes, err := client.ListUploadBuilds(&itchio.ListUploadBuildsParams{
			UploadID: upload.ID,
		})
		must(t, err)

		recentBuild := buildsRes.Builds[1]
		olderBuild := buildsRes.Builds[4]

		log("installing older build...")

		queue1Res, err := messages.InstallQueue.TestCall(rc, &butlerd.InstallQueueParams{
			Game:              game,
			InstallLocationID: "tmp",
			Upload:            upload,
			Build:             olderBuild,
		})
		must(t, err)

		caveId := queue1Res.CaveID
		assert.NotEmpty(t, caveId)

		_, err = messages.InstallPerform.TestCall(rc, &butlerd.InstallPerformParams{
			ID:            queue1Res.ID,
			StagingFolder: queue1Res.StagingFolder,
		})
		must(t, err)

		{
			_, err := os.Stat("./tmp/butler/.itch/receipt.json.gz")
			assert.NoError(t, err, "has receipt")
		}

		log("upgrading to next build...")

		queue2Res, err := messages.InstallQueue.TestCall(rc, &butlerd.InstallQueueParams{
			Game:              game,
			InstallLocationID: "tmp",
			CaveID:            caveId,
			Upload:            upload,
			Build:             recentBuild,
		})
		must(t, err)

		assert.EqualValues(t, queue1Res.CaveID, queue2Res.CaveID, "installing for same cave")
		assert.EqualValues(t, queue1Res.InstallFolder, queue2Res.InstallFolder, "using same install folder")

		_, err = messages.InstallPerform.TestCall(rc, &butlerd.InstallPerformParams{
			ID:            queue2Res.ID,
			StagingFolder: queue2Res.StagingFolder,
		})
		must(t, err)
	}
}
<commit_msg>fix integration test<commit_after>package integrate

import (
	"os"
	"testing"

	"github.com/itchio/butler/butlerd"
	"github.com/itchio/butler/butlerd/messages"
	itchio "github.com/itchio/go-itchio"
	"github.com/stretchr/testify/assert"
)

func Test_InstallUpdate(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping test in short mode")
	}

	log := func(msg string) {
		t.Logf("==========================")
		t.Logf("= %s", msg)
		t.Logf("==========================")
	}

	log("connecting to butlerd")

	rc, h, cancel := connect(t)
	defer cancel()

	authenticate(t, rc)
	setupTmpInstallLocation(t, h, rc)

	{
		log("listing builds...")

		// fasterthanlime/butler
		game := getGame(t, h, rc, 239683)

		client := itchio.ClientWithKey(os.Getenv("ITCH_TEST_ACCOUNT_API_KEY"))
		res, err := client.ListGameUploads(itchio.ListGameUploadsParams{
			GameID: game.ID,
		})
		must(t, err)

		var upload *itchio.Upload
		for _, u := range res.Uploads {
			if u.ChannelName == "darwin-amd64-head" {
				upload = u
				break
			}
		}
		assert.NotNil(t, upload)

		buildsRes, err := client.ListUploadBuilds(itchio.ListUploadBuildsParams{
			UploadID: upload.ID,
		})
		must(t, err)

		recentBuild := buildsRes.Builds[1]
		olderBuild := buildsRes.Builds[4]

		log("installing older build...")

		queue1Res, err := messages.InstallQueue.TestCall(rc, &butlerd.InstallQueueParams{
			Game:              game,
			InstallLocationID: "tmp",
			Upload:            upload,
			Build:             olderBuild,
		})
		must(t, err)

		caveId := queue1Res.CaveID
		assert.NotEmpty(t, caveId)

		_, err = messages.InstallPerform.TestCall(rc, &butlerd.InstallPerformParams{
			ID:            queue1Res.ID,
			StagingFolder: queue1Res.StagingFolder,
		})
		must(t, err)

		{
			_, err := os.Stat("./tmp/butler/.itch/receipt.json.gz")
			assert.NoError(t, err, "has receipt")
		}

		log("upgrading to next build...")

		queue2Res, err := messages.InstallQueue.TestCall(rc, &butlerd.InstallQueueParams{
			Game:              game,
			InstallLocationID: "tmp",
			CaveID:            caveId,
			Upload:            upload,
			Build:             recentBuild,
		})
		must(t, err)

		assert.EqualValues(t, queue1Res.CaveID, queue2Res.CaveID, "installing for same cave")
		assert.EqualValues(t, queue1Res.InstallFolder, queue2Res.InstallFolder, "using same install folder")

		_, err = messages.InstallPerform.TestCall(rc, &butlerd.InstallPerformParams{
			ID:            queue2Res.ID,
			StagingFolder: queue2Res.StagingFolder,
		})
		must(t, err)
	}
}

{'fraction_non_alphanumeric': 0.15690168818272096, 'fraction_numerical': 0.008341608738828202, 'mean_word_length': 3.315338474721508, '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': '3506424', 'n_tokens_mistral': 2041, 'n_tokens_neox': 1806, 'n_words': 330}