<commit_before><commit_msg>test: test that cache loading doesn't mangle shasum<commit_after>var npm = require.resolve("../../")
var test = require("tap").test
var path = require("path")
var fs = require("fs")
var rimraf = require("rimraf")
var mkdirp = require("mkdirp")
var mr = require("npm-registry-mock")
var common = require("../common-tap.js")
var cache = path.resolve(__dirname, "cache-shasum")
var spawn = require("child_process").spawn
var sha = require("sha")
var server

test("mock reg", function(t) {
  rimraf.sync(cache)
  mkdirp.sync(cache)
  mr(common.port, function (s) {
    server = s
    t.pass("ok")
    t.end()
  })
})

test("npm cache add request", function(t) {
  var c = spawn(process.execPath, [
    npm, "cache", "add", "request@2.27.0",
    "--cache=" + cache,
    "--registry=" + common.registry,
    "--loglevel=quiet"
  ])
  c.stderr.pipe(process.stderr)

  c.stdout.on("data", function(d) {
    t.fail("Should not get data on stdout: " + d)
  })

  c.on("close", function(code) {
    t.notOk(code, "exit ok")
    t.end()
  })
})

test("compare", function(t) {
  var d = path.resolve(__dirname, "cache-shasum/request")
  var p = path.resolve(d, "2.27.0/package.tgz")
  var r = require(path.resolve(d, ".cache.json"))
  var rshasum = r.versions['2.27.0'].dist.shasum
  sha.get(p, function (er, pshasum) {
    if (er)
      throw er
    t.equal(pshasum, rshasum)
    t.end()
  })
})

test("cleanup", function(t) {
  server.close()
  rimraf.sync(cache)
  t.end()
})
{'fraction_non_alphanumeric': 0.1950402144772118, 'fraction_numerical': 0.00804289544235925, 'mean_word_length': 3.551829268292683, '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': '6926558', 'n_tokens_mistral': 575, 'n_tokens_neox': 557, 'n_words': 121}