OK, but a bit verbose... This could just be:

var match = /(auto|impl|manual|unit)-test[^\/]*$/.exec(p);
return match ? match[1] : 'unknown';