<commit_before>// Copyright 2016 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.

// These tests all do one conflict-free operation while a user is unstaged.

package test

import (
	"testing"
	"time"
)

// bob writes a non-conflicting file while unstaged
func TestCrUnmergedFile(t *testing.T) {
	test(t,
		users("alice", "bob"),
		as(alice,
			mkfile("a/b", "hello"),
		),
		as(bob,
			disableUpdates(),
		),
		as(alice,
			write("a/c", "world"),
		),
		as(bob, noSync(),
			write("a/d", "uh oh"),
			reenableUpdates(),
			lsdir("a/", m{"b": "FILE", "c": "FILE", "d": "FILE"}),
			read("a/b", "hello"),
			read("a/c", "world"),
			read("a/d", "uh oh"),
		),
		as(alice,
			lsdir("a/", m{"b": "FILE", "c": "FILE", "d": "FILE"}),
			read("a/b", "hello"),
			read("a/c", "world"),
			read("a/d", "uh oh"),
		),
	)
}

// bob writes a non-conflicting dir (containing a file) while unstaged
func TestCrUnmergedDir(t *testing.T) {
	test(t,
		users("alice", "bob"),
		as(alice,
			mkfile("a/b", "hello"),
		),
		as(bob,
			disableUpdates(),
		),
		as(alice,
			write("a/c", "world"),
		),
		as(bob, noSync(),
			write("a/d/e", "uh oh"),
			reenableUpdates(),
			lsdir("a/", m{"b": "FILE", "c": "FILE", "d": "DIR"}),
			read("a/b", "hello"),
			read("a/c", "world"),
			lsdir("a/d", m{"e": "FILE"}),
			read("a/d/e", "uh oh"),
		),
		as(alice,
			lsdir("a/", m{"b": "FILE", "c": "FILE", "d": "DIR"}),
			read("a/b", "hello"),
			read("a/c", "world"),
			lsdir("a/d", m{"e": "FILE"}),
			read("a/d/e", "uh oh"),
		),
	)
}

// bob creates a non-conflicting symlink(while unstaged),
func TestCrUnmergedSymlink(t *testing.T) {
	test(t,
		skip("dokan", "Does not work with Dokan."),
		users("alice", "bob"),
		as(alice,
			mkfile("a/b", "hello"),
		),
		as(bob,
			disableUpdates(),
		),
		as(alice,
			write("a/c", "world"),
		),
		as(bob, noSync(),
			link("a/d", "b"),
			reenableUpdates(),
			lsdir("a/", m{"b": "FILE", "c": "FILE", "d": "SYM"}),
			read("a/b", "hello"),
			read("a/c", "world"),
			read("a/d", "hello"),
		),
		as(alice,
			lsdir("a/", m{"b": "FILE", "c": "FILE", "d": "SYM"}),
			read("a/b", "hello"),
			read("a/c", "world"),
			read("a/d", "hello"),
		),
	)
}

// bob makes a non-conflicting file executable while unstaged
func TestCrUnmergedSetex(t *testing.T) {
	test(t,
		users("alice", "bob"),
		as(alice,
			mkfile("a/b", "hello"),
		),
		as(bob,
			disableUpdates(),
		),
		as(alice,
			write("a/c", "world"),
		),
		as(bob, noSync(),
			setex("a/b", true),
			reenableUpdates(),
			lsdir("a/", m{"b": "EXEC", "c": "FILE"}),
			read("a/c", "world"),
		),
		as(alice,
			lsdir("a/", m{"b": "EXEC", "c": "FILE"}),
			read("a/c", "world"),
		),
	)
}

// bob sets the mtime on a file while unstaged
func TestCrUnmergedSetMtime(t *testing.T) {
	targetMtime := time.Now().Add(1 * time.Minute)
	test(t,
		users("alice", "bob"),
		as(alice,
			mkfile("a/b", "hello"),
		),
		as(bob,
			disableUpdates(),
		),
		as(alice,
			write("a/c", "world"),
		),
		as(bob, noSync(),
			setmtime("a/b", targetMtime),
			reenableUpdates(),
			lsdir("a/", m{"b": "FILE", "c": "FILE"}),
			read("a/c", "world"),
			mtime("a/b", targetMtime),
		),
		as(alice,
			lsdir("a/", m{"b": "FILE", "c": "FILE"}),
			read("a/c", "world"),
			mtime("a/b", targetMtime),
		),
	)
}

// bob sets the mtime on a file while unstaged
func TestCrUnmergedSetMtimeInNewDir(t *testing.T) {
	targetMtime := time.Now().Add(1 * time.Minute)
	test(t,
		users("alice", "bob"),
		as(alice,
			mkfile("a/b", "hello"),
		),
		as(bob,
			disableUpdates(),
		),
		as(alice,
			write("a/c", "world"),
		),
		as(bob, noSync(),
			mkdir("d"),
			mkdir("d/e"),
			setmtime("d/e", targetMtime),
			reenableUpdates(),
			lsdir("a/", m{"b": "FILE", "c": "FILE"}),
			read("a/c", "world"),
			lsdir("d/", m{"e": "DIR"}),
			mtime("d/e", targetMtime),<commit_msg>test: regression test comment for TestCrUnmergedSetMtimeInNewDir<commit_after>// Copyright 2016 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.

// These tests all do one conflict-free operation while a user is unstaged.

package test

import (
	"testing"
	"time"
)

// bob writes a non-conflicting file while unstaged
func TestCrUnmergedFile(t *testing.T) {
	test(t,
		users("alice", "bob"),
		as(alice,
			mkfile("a/b", "hello"),
		),
		as(bob,
			disableUpdates(),
		),
		as(alice,
			write("a/c", "world"),
		),
		as(bob, noSync(),
			write("a/d", "uh oh"),
			reenableUpdates(),
			lsdir("a/", m{"b": "FILE", "c": "FILE", "d": "FILE"}),
			read("a/b", "hello"),
			read("a/c", "world"),
			read("a/d", "uh oh"),
		),
		as(alice,
			lsdir("a/", m{"b": "FILE", "c": "FILE", "d": "FILE"}),
			read("a/b", "hello"),
			read("a/c", "world"),
			read("a/d", "uh oh"),
		),
	)
}

// bob writes a non-conflicting dir (containing a file) while unstaged
func TestCrUnmergedDir(t *testing.T) {
	test(t,
		users("alice", "bob"),
		as(alice,
			mkfile("a/b", "hello"),
		),
		as(bob,
			disableUpdates(),
		),
		as(alice,
			write("a/c", "world"),
		),
		as(bob, noSync(),
			write("a/d/e", "uh oh"),
			reenableUpdates(),
			lsdir("a/", m{"b": "FILE", "c": "FILE", "d": "DIR"}),
			read("a/b", "hello"),
			read("a/c", "world"),
			lsdir("a/d", m{"e": "FILE"}),
			read("a/d/e", "uh oh"),
		),
		as(alice,
			lsdir("a/", m{"b": "FILE", "c": "FILE", "d": "DIR"}),
			read("a/b", "hello"),
			read("a/c", "world"),
			lsdir("a/d", m{"e": "FILE"}),
			read("a/d/e", "uh oh"),
		),
	)
}

// bob creates a non-conflicting symlink(while unstaged),
func TestCrUnmergedSymlink(t *testing.T) {
	test(t,
		skip("dokan", "Does not work with Dokan."),
		users("alice", "bob"),
		as(alice,
			mkfile("a/b", "hello"),
		),
		as(bob,
			disableUpdates(),
		),
		as(alice,
			write("a/c", "world"),
		),
		as(bob, noSync(),
			link("a/d", "b"),
			reenableUpdates(),
			lsdir("a/", m{"b": "FILE", "c": "FILE", "d": "SYM"}),
			read("a/b", "hello"),
			read("a/c", "world"),
			read("a/d", "hello"),
		),
		as(alice,
			lsdir("a/", m{"b": "FILE", "c": "FILE", "d": "SYM"}),
			read("a/b", "hello"),
			read("a/c", "world"),
			read("a/d", "hello"),
		),
	)
}

// bob makes a non-conflicting file executable while unstaged
func TestCrUnmergedSetex(t *testing.T) {
	test(t,
		users("alice", "bob"),
		as(alice,
			mkfile("a/b", "hello"),
		),
		as(bob,
			disableUpdates(),
		),
		as(alice,
			write("a/c", "world"),
		),
		as(bob, noSync(),
			setex("a/b", true),
			reenableUpdates(),
			lsdir("a/", m{"b": "EXEC", "c": "FILE"}),
			read("a/c", "world"),
		),
		as(alice,
			lsdir("a/", m{"b": "EXEC", "c": "FILE"}),
			read("a/c", "world"),
		),
	)
}

// bob sets the mtime on a file while unstaged
func TestCrUnmergedSetMtime(t *testing.T) {
	targetMtime := time.Now().Add(1 * time.Minute)
	test(t,
		users("alice", "bob"),
		as(alice,
			mkfile("a/b", "hello"),
		),
		as(bob,
			disableUpdates(),
		),
		as(alice,
			write("a/c", "world"),
		),
		as(bob, noSync(),
			setmtime("a/b", targetMtime),
			reenableUpdates(),
			lsdir("a/", m{"b": "FILE", "c": "FILE"}),
			read("a/c", "world"),
			mtime("a/b", targetMtime),
		),
		as(alice,
			lsdir("a/", m{"b": "FILE", "c": "FILE"}),
			read("a/c", "world"),
			mtime("a/b", targetMtime),
		),
	)
}

// bob sets the mtime on a file in a newly-created directory while
// unstaged.  Regression test for KBFS-2162.
func TestCrUnmergedSetMtimeInNewDir(t *testing.T) {
	targetMtime := time.Now().Add(1 * time.Minute)
	test(t,
		users("alice", "bob"),
		as(alice,
			mkfile("a/b", "hello"),
		),
		as(bob,
			disableUpdates(),
		),
		as(alice,
			write("a/c", "world"),
		),
		as(bob, noSync(),
			mkdir("d"),
			mkdir("d/e"),
			setmtime("d/e", targetMtime),
			reenableUpdates(),
			lsdir("a/", m{"b": "FILE", "c": "FILE"}),
			read("a/c", "world"),
			lsdir("d/", m{"e": "DIR"}),
			mtime("d/e", targetMtime),
{'fraction_non_alphanumeric': 0.2625, 'fraction_numerical': 0.00202020202020202, 'mean_word_length': 3.395671476137625, 'pattern_counts': {'":': 62, '<': 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': '1270285', 'n_tokens_mistral': 3903, 'n_tokens_neox': 3391, 'n_words': 732}